Skip to content

Commit 29b7198

Browse files
committed
Fix to ensure that asyncio uses SaltLoggingClass
Fixes the salt logging implementation to check asyncio is using the SaltLoggingClass if it has already been imported. If it uses the standard logging.Logger() class then extra fields in the log format such as %(jid)s will cause an exception when asyncio logs anything.
1 parent d700012 commit 29b7198

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

changelog/68400.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes issue with asyncio logger not using SaltLoggingClass and causing exceptions when "%(jid)s" is used in a log format.

salt/_logging/impl.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ def shutdown_temp_handler():
559559
logging.root.addHandler(get_temp_handler())
560560

561561

562+
# Override asyncio logger class if asyncio is already imported
563+
if "asyncio" in sys.modules:
564+
asyncio_logger = logging.getLogger("asyncio")
565+
if not isinstance(asyncio_logger, SaltLoggingClass):
566+
asyncio_logger.__class__ = SaltLoggingClass
567+
568+
562569
# Now that we defined the default logging logger class, we can instantiate our logger
563570
# DO NOT MOVE THIS
564571
log = logging.getLogger(__name__)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Tests to ensure asyncio logger uses SaltLoggingClass
3+
"""
4+
5+
import logging
6+
7+
8+
def test_asyncio_logger_saltloggingclass():
9+
"""
10+
Test that the asyncio logger is an instance of SaltLoggingClass
11+
12+
It is imported before salt._logging so we need to ensure it is overridden
13+
"""
14+
15+
asyncio_logger = logging.getLogger("asyncio")
16+
17+
import salt._logging.impl
18+
19+
assert isinstance(asyncio_logger, salt._logging.impl.SaltLoggingClass)

0 commit comments

Comments
 (0)