Skip to content

[3.12] gh-118868: logging QueueHandler fix passing of kwargs (GH-118869) #120031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed issue where kwargs were no longer passed to the logging handler
QueueHandler
Loading