https://github.com/python/cpython/commit/2b68c81283a8a7d2e09f9ca774048181c872471b
commit: 2b68c81283a8a7d2e09f9ca774048181c872471b
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vsajip <[email protected]>
date: 2024-04-17T14:48:09+01:00
summary:
[3.12] gh-117975: Ensure flush level is checked when configuring a logging
MemoryHandler. (GH-117976) (GH-117986)
(cherry picked from commit 6d0bb43232dd6ebc5245daa4fe29f07f815f0bad)
files:
M Lib/logging/config.py
M Lib/test/test_logging.py
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 33417b75d51935..2c0d30ccf80692 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -768,18 +768,20 @@ def configure_handler(self, config):
klass = cname
else:
klass = self.resolve(cname)
- if issubclass(klass, logging.handlers.MemoryHandler) and\
- 'target' in config:
- # Special case for handler which refers to another handler
- try:
- tn = config['target']
- th = self.config['handlers'][tn]
- if not isinstance(th, logging.Handler):
- config.update(config_copy) # restore for deferred cfg
- raise TypeError('target not configured yet')
- config['target'] = th
- except Exception as e:
- raise ValueError('Unable to set target handler %r' % tn)
from e
+ if issubclass(klass, logging.handlers.MemoryHandler):
+ if 'flushLevel' in config:
+ config['flushLevel'] =
logging._checkLevel(config['flushLevel'])
+ if 'target' in config:
+ # Special case for handler which refers to another handler
+ try:
+ tn = config['target']
+ th = self.config['handlers'][tn]
+ if not isinstance(th, logging.Handler):
+ config.update(config_copy) # restore for deferred
cfg
+ raise TypeError('target not configured yet')
+ config['target'] = th
+ except Exception as e:
+ raise ValueError('Unable to set target handler %r' %
tn) from e
elif issubclass(klass, logging.handlers.QueueHandler):
# Another special case for handler which refers to other
handlers
# if 'handlers' not in config:
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index a4b2b4f9c8fd40..cf9fd427be2f91 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3050,6 +3050,30 @@ def format(self, record):
},
}
+ config18 = {
+ "version": 1,
+ "handlers": {
+ "console": {
+ "class": "logging.StreamHandler",
+ "level": "DEBUG",
+ },
+ "buffering": {
+ "class": "logging.handlers.MemoryHandler",
+ "capacity": 5,
+ "target": "console",
+ "level": "DEBUG",
+ "flushLevel": "ERROR"
+ }
+ },
+ "loggers": {
+ "mymodule": {
+ "level": "DEBUG",
+ "handlers": ["buffering"],
+ "propagate": "true"
+ }
+ }
+ }
+
bad_format = {
"version": 1,
"formatters": {
@@ -3536,6 +3560,11 @@ def test_config17_ok(self):
h = logging._handlers['hand1']
self.assertEqual(h.formatter.custom_property, 'value')
+ def test_config18_ok(self):
+ self.apply_config(self.config18)
+ handler = logging.getLogger('mymodule').handlers[0]
+ self.assertEqual(handler.flushLevel, logging.ERROR)
+
def setup_via_listener(self, text, verify=None):
text = text.encode("utf-8")
# Ask for a randomly assigned port (by using port 0)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]