Skip to content

Commit 86b714f

Browse files
Fix ConfigLoggingUpdater not changing root logging level
Setting log level with method `logging.basicConfig` during runtime is not working. Instead logging.getLogger() is used.
1 parent 53792f2 commit 86b714f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
## Bug Fixes
1616

17-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
17+
* Fix bug with LoggingConfigUpdater not updating root logger level.

src/frequenz/sdk/config/_logging_config_updater.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,16 @@ def __init__(
144144
"""
145145
super().__init__()
146146
self._config_recv = config_recv
147-
self._format = log_format
148-
self._datefmt = log_datefmt
149147

150148
# Setup default configuration.
151149
# This ensures logging is configured even if actor fails to start or
152150
# if the configuration cannot be loaded.
153151
self._current_config: LoggingConfig = LoggingConfig()
152+
153+
logging.basicConfig(
154+
format=log_format,
155+
datefmt=log_datefmt,
156+
)
154157
self._update_logging(self._current_config)
155158

156159
async def _run(self) -> None:
@@ -176,11 +179,10 @@ def _update_logging(self, config: LoggingConfig) -> None:
176179
logging.getLogger(logger_id).setLevel(logging.NOTSET)
177180

178181
self._current_config = config
179-
logging.basicConfig(
180-
format=self._format,
181-
level=self._current_config.root_logger.level,
182-
datefmt=self._datefmt,
182+
_logger.debug(
183+
"Setting root logger level to '%s'", self._current_config.root_logger.level
183184
)
185+
logging.getLogger().setLevel(self._current_config.root_logger.level)
184186

185187
# For each logger in the new config, set the log level
186188
for logger_id, logger_config in self._current_config.loggers.items():

0 commit comments

Comments
 (0)