summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Nemec <bnemec@redhat.com>2019-08-14 16:02:23 +0000
committerBen Nemec <bnemec@redhat.com>2019-08-14 16:02:23 +0000
commit500788981e1abcd5a495badac350285e39f993a4 (patch)
tree03467d44a565391bc944dc6802f5623989e11ce6
parent9222660a461967c90341d6fd2aebfd4259753ebc (diff)
downloadoslo-log-500788981e1abcd5a495badac350285e39f993a4.tar.gz
Use setLevel instead of setting logger.level directly
Python 3.7 added caching of the log level for calls to isEnabledFor on a logger[0]. As a result, modifying the logger level directly can cause a mismatch in behavior if a log call was made prior to that modification. In our case, we were calling logger.info before the info level was enabled, which meant the logger cached the fact that it was not enabled for info-level logging. Even after setting the level to NOTSET, it was still remembering that it shouldn't log info messages and that breaks our unit tests on py37. There is a related issue open against Python[1], but basically the answer there was "don't mess with logger internals". The simple fix is to use logger.setLevel for resetting the log level instead of modifying the attribute directly. Change-Id: Ifd1300d8e4280df1913f632e964f9458dbb2db55 0: https://github.com/python/cpython/commit/78c18a9b9a1445f7c755929917a790ba02b4a5e0#diff-5bd69232a06838f179312d3e48ccf506 1: https://bugs.python.org/issue34269 Closes-Bug: 1783630
-rw-r--r--oslo_log/log.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/oslo_log/log.py b/oslo_log/log.py
index 8cf5d49..479c4a8 100644
--- a/oslo_log/log.py
+++ b/oslo_log/log.py
@@ -226,7 +226,7 @@ def _load_log_config(log_config_append):
# Reset all existing loggers before reloading config as fileConfig
# does not reset non-child loggers.
for logger in _iter_loggers():
- logger.level = logging.NOTSET
+ logger.setLevel(logging.NOTSET)
logger.handlers = []
logger.propagate = 1
logging.config.fileConfig(log_config_append,