mirror of
https://github.com/python/cpython.git
synced 2025-08-10 20:08:47 +00:00
[3.12] gh-117975: Ensure flush level is checked when configuring a logging MemoryHandler. (GH-117976) (GH-117986)
(cherry picked from commit 6d0bb43232
)
This commit is contained in:
parent
c270caf966
commit
2b68c81283
2 changed files with 43 additions and 12 deletions
|
@ -768,18 +768,20 @@ class DictConfigurator(BaseConfigurator):
|
||||||
klass = cname
|
klass = cname
|
||||||
else:
|
else:
|
||||||
klass = self.resolve(cname)
|
klass = self.resolve(cname)
|
||||||
if issubclass(klass, logging.handlers.MemoryHandler) and\
|
if issubclass(klass, logging.handlers.MemoryHandler):
|
||||||
'target' in config:
|
if 'flushLevel' in config:
|
||||||
# Special case for handler which refers to another handler
|
config['flushLevel'] = logging._checkLevel(config['flushLevel'])
|
||||||
try:
|
if 'target' in config:
|
||||||
tn = config['target']
|
# Special case for handler which refers to another handler
|
||||||
th = self.config['handlers'][tn]
|
try:
|
||||||
if not isinstance(th, logging.Handler):
|
tn = config['target']
|
||||||
config.update(config_copy) # restore for deferred cfg
|
th = self.config['handlers'][tn]
|
||||||
raise TypeError('target not configured yet')
|
if not isinstance(th, logging.Handler):
|
||||||
config['target'] = th
|
config.update(config_copy) # restore for deferred cfg
|
||||||
except Exception as e:
|
raise TypeError('target not configured yet')
|
||||||
raise ValueError('Unable to set target handler %r' % tn) from e
|
config['target'] = th
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError('Unable to set target handler %r' % tn) from e
|
||||||
elif issubclass(klass, logging.handlers.QueueHandler):
|
elif issubclass(klass, logging.handlers.QueueHandler):
|
||||||
# Another special case for handler which refers to other handlers
|
# Another special case for handler which refers to other handlers
|
||||||
# if 'handlers' not in config:
|
# if 'handlers' not in config:
|
||||||
|
|
|
@ -3050,6 +3050,30 @@ class ConfigDictTest(BaseTest):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = {
|
bad_format = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"formatters": {
|
"formatters": {
|
||||||
|
@ -3536,6 +3560,11 @@ class ConfigDictTest(BaseTest):
|
||||||
h = logging._handlers['hand1']
|
h = logging._handlers['hand1']
|
||||||
self.assertEqual(h.formatter.custom_property, 'value')
|
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):
|
def setup_via_listener(self, text, verify=None):
|
||||||
text = text.encode("utf-8")
|
text = text.encode("utf-8")
|
||||||
# Ask for a randomly assigned port (by using port 0)
|
# Ask for a randomly assigned port (by using port 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue