summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorMario Corchero <mcorcherojim@bloomberg.net>2022-01-24 12:39:50 (GMT)
committerGitHub <noreply@github.com>2022-01-24 12:39:50 (GMT)
commitd7c68639795a576ff58b6479c8bb34c113df3618 (patch)
treecb14dbe941f837f0c36f785c59d9d22b9d1fccca /Lib/logging
parent58f3d980989c7346ad792d464c1d749dcec6af63 (diff)
downloadcpython-d7c68639795a576ff58b6479c8bb34c113df3618.zip
cpython-d7c68639795a576ff58b6479c8bb34c113df3618.tar.gz
cpython-d7c68639795a576ff58b6479c8bb34c113df3618.tar.bz2
bpo-41906: Accept built filters in dictConfig (GH-30756)
When configuring the logging stack, accept already built filters (or just callables) in the filters array of loggers and handlers. This facilitates passing quick callables as filters. Automerge-Triggered-By: GH:vsajip
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/config.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 9bc07ed..86a1e4e 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -694,7 +694,11 @@ class DictConfigurator(BaseConfigurator):
"""Add filters to a filterer from a list of names."""
for f in filters:
try:
- filterer.addFilter(self.config['filters'][f])
+ if callable(f) or callable(getattr(f, 'filter', None)):
+ filter_ = f
+ else:
+ filter_ = self.config['filters'][f]
+ filterer.addFilter(filter_)
except Exception as e:
raise ValueError('Unable to add filter %r' % f) from e