summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-04 12:18:11 (GMT)
committerGitHub <noreply@github.com>2024-06-04 12:18:11 (GMT)
commitfeaecf8c33444d44a5a554680f270c5c614185d3 (patch)
tree9065e7999761933f6ebbe89e5940e57e29e01d61 /Lib
parent6ce2810f36829ae89278219ec89f3cc798f19ae6 (diff)
downloadcpython-feaecf8c33444d44a5a554680f270c5c614185d3.zip
cpython-feaecf8c33444d44a5a554680f270c5c614185d3.tar.gz
cpython-feaecf8c33444d44a5a554680f270c5c614185d3.tar.bz2
[3.13] gh-118868: logging QueueHandler fix passing of kwargs (GH-118869) (GH-120032)
(cherry picked from commit dce14bb2dce7887df40ae5c13b0d13e0dafceff7)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/config.py16
-rw-r--r--Lib/test/test_logging.py29
2 files changed, 37 insertions, 8 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 860e475..ac45d68 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -725,16 +725,16 @@ class DictConfigurator(BaseConfigurator):
def _configure_queue_handler(self, klass, **kwargs):
if 'queue' in kwargs:
- q = kwargs['queue']
+ q = kwargs.pop('queue')
else:
q = queue.Queue() # unbounded
- rhl = kwargs.get('respect_handler_level', False)
- if 'listener' in kwargs:
- lklass = kwargs['listener']
- else:
- lklass = logging.handlers.QueueListener
- listener = lklass(q, *kwargs.get('handlers', []), respect_handler_level=rhl)
- handler = klass(q)
+
+ rhl = kwargs.pop('respect_handler_level', False)
+ lklass = kwargs.pop('listener', logging.handlers.QueueListener)
+ handlers = kwargs.pop('handlers', [])
+
+ listener = lklass(q, *handlers, respect_handler_level=rhl)
+ handler = klass(q, **kwargs)
handler.listener = listener
return handler
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 97d7c9f..9ebd345 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3976,6 +3976,35 @@ class ConfigDictTest(BaseTest):
}
logging.config.dictConfig(config)
+ # gh-118868: check if kwargs are passed to logging QueueHandler
+ def test_kwargs_passing(self):
+ class CustomQueueHandler(logging.handlers.QueueHandler):
+ def __init__(self, *args, **kwargs):
+ super().__init__(queue.Queue())
+ self.custom_kwargs = kwargs
+
+ custom_kwargs = {'foo': 'bar'}
+
+ config = {
+ 'version': 1,
+ 'handlers': {
+ 'custom': {
+ 'class': CustomQueueHandler,
+ **custom_kwargs
+ },
+ },
+ 'root': {
+ 'level': 'DEBUG',
+ 'handlers': ['custom']
+ }
+ }
+
+ logging.config.dictConfig(config)
+
+ handler = logging.getHandlerByName('custom')
+ self.assertEqual(handler.custom_kwargs, custom_kwargs)
+
+
class ManagerTest(BaseTest):
def test_manager_loggerclass(self):
logged = []