https://github.com/python/cpython/commit/fe68908c54103f391daa22963b017843ec63d63e
commit: fe68908c54103f391daa22963b017843ec63d63e
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vsajip <[email protected]>
date: 2024-06-04T13:17:46+01:00
summary:
[3.12] gh-118868: logging QueueHandler fix passing of kwargs (GH-118869)
(GH-120031)
(cherry picked from commit dce14bb2dce7887df40ae5c13b0d13e0dafceff7)
files:
A Misc/NEWS.d/next/Library/2024-05-09-21-36-11.gh-issue-118868.uckxxP.rst
M Lib/logging/config.py
M Lib/test/test_logging.py
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 2c0d30ccf80692..3aec8361aeff6e 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -732,16 +732,16 @@ def add_filters(self, filterer, filters):
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 5a9772dffafb85..fa455035e5c41d 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3944,6 +3944,35 @@ def test_111615(self):
}
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 = []
diff --git
a/Misc/NEWS.d/next/Library/2024-05-09-21-36-11.gh-issue-118868.uckxxP.rst
b/Misc/NEWS.d/next/Library/2024-05-09-21-36-11.gh-issue-118868.uckxxP.rst
new file mode 100644
index 00000000000000..372a809d9594b0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-09-21-36-11.gh-issue-118868.uckxxP.rst
@@ -0,0 +1,2 @@
+Fixed issue where kwargs were no longer passed to the logging handler
+QueueHandler
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]