Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for applying logging configurations using the a TOML configuration file #3237

Merged
merged 6 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion luigi/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os.path

from luigi.configuration import get_config, LuigiConfigParser
from luigi.freezing import recursively_unfreeze

from configparser import NoSectionError

Expand All @@ -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
Expand Down
37 changes: 33 additions & 4 deletions test/setup_logging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,39 @@ 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',
},
},
'loggers': {
'mocklogger': {
'handlers': ('mockhandler',),
'level': 'INFO',
'disabled': False,
'propagate': False,
},
},
},
}
result = self.cls._section(None)
self.assertTrue(result)

self.cls.config = LuigiTomlParser()
self.cls.config.read(['./test/testconfig/luigi_logging.toml'])
result = self.cls._section(None)
self.assertTrue(result)

Expand Down
18 changes: 18 additions & 0 deletions test/testconfig/luigi_logging.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[logging]
version = 1
disable_existing_loggers = false

[logging.formatters.mockformatter]
format = "{levelname}: {message}"
style = "{"

[logging.handlers.mockhandler]
class = "logging.StreamHandler"
level = "INFO"
formatter = "mockformatter"

[logging.loggers.mocklogger]
handlers = ["mockhandler"]
level = 'INFO'
disabled = false
propagate = false