From ab60b3ee502e99ebd166bb567cd86d4070160132 Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Tue, 24 May 2022 10:54:19 +0200 Subject: [PATCH 1/2] Add option to pass instances in dict --- Lib/logging/config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 86a1e4eaf4cbc9..10a4f749c1568c 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -647,6 +647,9 @@ def configure(self): def configure_formatter(self, config): """Configure a formatter from a dictionary.""" + if isinstance(config, logging.Formatter): + return config + if '()' in config: factory = config['()'] # for use in exception handler try: @@ -683,6 +686,9 @@ def configure_formatter(self, config): def configure_filter(self, config): """Configure a filter from a dictionary.""" + if isinstance(config, logging.Filter): + return config + if '()' in config: result = self.configure_custom(config) else: @@ -744,7 +750,7 @@ def configure_handler(self, config): props = config.pop('.', None) kwargs = {k: config[k] for k in config if valid_ident(k)} try: - result = factory(**kwargs) + result = factory(**kwargs) if not isinstance(factory, logging.Handler) else factory except TypeError as te: if "'stream'" not in str(te): raise From 242f8d3fcf09c0e4a750a56a2baa78d7221f697c Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Tue, 24 May 2022 11:27:03 +0200 Subject: [PATCH 2/2] add news --- .../next/Library/2022-05-24-11-26-31.gh-issue-93162.3YuOur.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-24-11-26-31.gh-issue-93162.3YuOur.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-24-11-26-31.gh-issue-93162.3YuOur.rst b/Misc/NEWS.d/next/Library/2022-05-24-11-26-31.gh-issue-93162.3YuOur.rst new file mode 100644 index 00000000000000..000767c73a7a6c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-24-11-26-31.gh-issue-93162.3YuOur.rst @@ -0,0 +1 @@ +Allow passing instances of logging objects to logging.dictConfig