diff --git a/changelog/68400.fixed.md b/changelog/68400.fixed.md new file mode 100644 index 000000000000..763c76de20c8 --- /dev/null +++ b/changelog/68400.fixed.md @@ -0,0 +1 @@ +Fixes issue with asyncio logger not using SaltLoggingClass and causing exceptions when "%(jid)s" is used in a log format. diff --git a/salt/_logging/impl.py b/salt/_logging/impl.py index c4de686f1976..12b36c5da87e 100644 --- a/salt/_logging/impl.py +++ b/salt/_logging/impl.py @@ -559,6 +559,13 @@ def shutdown_temp_handler(): logging.root.addHandler(get_temp_handler()) +# Override asyncio logger class if asyncio is already imported +if "asyncio" in sys.modules: + asyncio_logger = logging.getLogger("asyncio") + if not isinstance(asyncio_logger, SaltLoggingClass): + asyncio_logger.__class__ = SaltLoggingClass + + # Now that we defined the default logging logger class, we can instantiate our logger # DO NOT MOVE THIS log = logging.getLogger(__name__) diff --git a/tests/pytests/unit/_logging/test_asyncio_logger.py b/tests/pytests/unit/_logging/test_asyncio_logger.py new file mode 100644 index 000000000000..d2b42af1ea53 --- /dev/null +++ b/tests/pytests/unit/_logging/test_asyncio_logger.py @@ -0,0 +1,19 @@ +""" +Tests to ensure asyncio logger uses SaltLoggingClass +""" + +import logging + + +def test_asyncio_logger_saltloggingclass(): + """ + Test that the asyncio logger is an instance of SaltLoggingClass + + It is imported before salt._logging so we need to ensure it is overridden + """ + + asyncio_logger = logging.getLogger("asyncio") + + import salt._logging.impl + + assert isinstance(asyncio_logger, salt._logging.impl.SaltLoggingClass)