From 52bd8229a5972fa2873e46167f09b52f4a375203 Mon Sep 17 00:00:00 2001 From: JoseHJBlanco Date: Wed, 19 Apr 2023 15:28:44 -0300 Subject: [PATCH] Solve issue with TOML parser configuring formatters and other logging options --- luigi/setup_logging.py | 3 ++- test/setup_logging_test.py | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/luigi/setup_logging.py b/luigi/setup_logging.py index 60ff39dc83..fdda06b79c 100644 --- a/luigi/setup_logging.py +++ b/luigi/setup_logging.py @@ -24,6 +24,7 @@ import os.path from luigi.configuration import get_config, LuigiConfigParser +from luigi.freezing import recursively_unfreeze from configparser import NoSectionError @@ -40,7 +41,7 @@ def _section(cls, opts): logging_config = cls.config['logging'] except (TypeError, KeyError, NoSectionError): return False - logging.config.dictConfig(logging_config) + logging.config.dictConfig(recursively_unfreeze(logging_config)) return True @classmethod diff --git a/test/setup_logging_test.py b/test/setup_logging_test.py index 3bc17462f0..5e459de464 100644 --- a/test/setup_logging_test.py +++ b/test/setup_logging_test.py @@ -31,10 +31,34 @@ def test_cli(self): self.assertFalse(result) def test_section(self): - self.cls.config = {'logging': { - 'version': 1, - 'disable_existing_loggers': False, - }} + self.cls.config = { + 'logging': { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'mockformatter': { + 'format': '{levelname}: {message}', + 'style': '{', + 'datefmt': '%Y-%m-%d %H:%M:%S', + }, + }, + 'handlers': { + 'mockhandler': { + 'class': 'logging.StreamHandler', + 'level': 'INFO', + 'formatter': 'mockformatter', + }, + }, + 'mockloggers': { + 'mocklogger': { + 'handlers': ('mockhandler',), + 'level': 'INFO', + 'disabled': False, + 'propagate': False, + }, + }, + }, + } result = self.cls._section(None) self.assertTrue(result)