diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2023-12-27 09:35:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 09:35:15 (GMT) |
commit | 67655d8ad5de8666c97b0a377c6141a6abf66350 (patch) | |
tree | b001494b7bd8bb41bff394db1eabb01dd12f1c2f /Lib/logging | |
parent | 00cdd416fc60876ff21d9eafdc5d5d7a91737db5 (diff) | |
download | cpython-67655d8ad5de8666c97b0a377c6141a6abf66350.zip cpython-67655d8ad5de8666c97b0a377c6141a6abf66350.tar.gz cpython-67655d8ad5de8666c97b0a377c6141a6abf66350.tar.bz2 |
gh-111615: Fix regression in QueueHandler configuration. (GH-111638)
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/config.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 4b520e3..de06090 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -1,4 +1,4 @@ -# Copyright 2001-2022 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2023 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -734,7 +734,7 @@ class DictConfigurator(BaseConfigurator): lklass = kwargs['listener'] else: lklass = logging.handlers.QueueListener - listener = lklass(q, *kwargs['handlers'], respect_handler_level=rhl) + listener = lklass(q, *kwargs.get('handlers', []), respect_handler_level=rhl) handler = klass(q) handler.listener = listener return handler @@ -776,11 +776,12 @@ class DictConfigurator(BaseConfigurator): 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: - raise ValueError('No handlers specified for a QueueHandler') + # if 'handlers' not in config: + # raise ValueError('No handlers specified for a QueueHandler') if 'queue' in config: + from multiprocessing.queues import Queue as MPQueue qspec = config['queue'] - if not isinstance(qspec, queue.Queue): + if not isinstance(qspec, (queue.Queue, MPQueue)): if isinstance(qspec, str): q = self.resolve(qspec) if not callable(q): @@ -813,18 +814,19 @@ class DictConfigurator(BaseConfigurator): if not callable(listener): raise TypeError('Invalid listener specifier %r' % lspec) config['listener'] = listener - hlist = [] - try: - for hn in config['handlers']: - h = self.config['handlers'][hn] - if not isinstance(h, logging.Handler): - config.update(config_copy) # restore for deferred cfg - raise TypeError('Required handler %r ' - 'is not configured yet' % hn) - hlist.append(h) - except Exception as e: - raise ValueError('Unable to set required handler %r' % hn) from e - config['handlers'] = hlist + if 'handlers' in config: + hlist = [] + try: + for hn in config['handlers']: + h = self.config['handlers'][hn] + if not isinstance(h, logging.Handler): + config.update(config_copy) # restore for deferred cfg + raise TypeError('Required handler %r ' + 'is not configured yet' % hn) + hlist.append(h) + except Exception as e: + raise ValueError('Unable to set required handler %r' % hn) from e + config['handlers'] = hlist elif issubclass(klass, logging.handlers.SMTPHandler) and\ 'mailhost' in config: config['mailhost'] = self.as_tuple(config['mailhost']) |