-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-35726:QueueHandler formatting affects other handlers #11537
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Zheaoli, thanks for your contribution !
Tests for the logging
module do not pass anymore, can you look into it?
@remilapeyre I have already fixed the test error! This PR could be reviewed and merged right now. |
this PR needs backport to 3.0-3.7 and 2.7 |
Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Library/2019-01-13-01-33-00.bpo-35726.dasdas.rst
Outdated
Show resolved
Hide resolved
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
I have made the requested changes; please review again |
Thanks for making the requested changes! @vsajip: please review the changes made to this pull request. |
QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain.
I have made the requested changes; please review again |
Thanks for making the requested changes! @vsajip: please review the changes made to this pull request. |
@vsajip this PR need be back to Python 3.5/3.6/3.7 |
3.5 and 3.6 are in security fixes only mode so this can be backported only to 3.7. |
@tirkarthi Got it, thx |
@Zheaoli @vsajip I am just curious if there is a test for this in import queue
import logging
from logging import handlers
queue = queue.Queue(-1)
que_hdlr = handlers.QueueHandler(queue)
stream_hdlr = logging.StreamHandler()
logger = logging.getLogger(__name__)
queue_log_format = "Queue %(name)s -> %(levelname)s: %(message)s"
queue_formatter = logging.Formatter(queue_log_format)
stream_log_format = "Stream %(name)s -> %(levelname)s: %(message)s"
stream_formatter = logging.Formatter(stream_log_format)
stream_hdlr.setFormatter(stream_formatter)
que_hdlr.setFormatter(queue_formatter)
listener = handlers.QueueListener(queue, que_hdlr)
listener.start()
logger.setLevel(logging.WARNING)
logger.addHandler(que_hdlr)
logger.addHandler(stream_hdlr)
logger.exception("hello") ➜ cpython git:(master) ✗ python3.7 /tmp/foo.py
Stream __main__ -> ERROR: Queue __main__ -> ERROR: hello
NoneType: None
➜ cpython git:(master) ✗ ./python.exe /tmp/foo.py # patched master
Stream __main__ -> ERROR: hello
NoneType: None |
I can raise a PR something along the lines of below if there is a confirmation that there are no tests for the current PR. @unittest.skipUnless(hasattr(logging.handlers, 'QueueListener'),
'logging.handlers.QueueListener required for this test')
def test_queue_listener_with_multiple_handlers(self):
# Test that queue handler format doesn't affect other handler formats ([bpo-35726](https://bugs.python.org/issue35726)).
self.que_hdlr.setFormatter(self.root_formatter)
self.que_logger.addHandler(self.root_hdlr)
listener = logging.handlers.QueueListener(self.queue, self.que_hdlr)
listener.start()
self.que_logger.error("error")
listener.stop()
self.assertEqual(self.stream.getvalue().strip(), "que -> ERROR: error")
|
A PR with a test would be good, thanks. I don't believe there was a test for this specific case. |
…er handlers (pythonGH-11537) QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain. (cherry picked from commit da6424e) Co-authored-by: Manjusaka <[email protected]>
GH-12716 is a backport of this pull request to the 3.7 branch. |
…er handlers (GH-11537) (GH-12716) QueueHandler.prepare() now makes a copy of the record before modifying and enqueueing it, to avoid affecting other handlers in the chain. (cherry picked from commit da6424e) Co-authored-by: Manjusaka <[email protected]>
https://bugs.python.org/issue35726
https://bugs.python.org/issue35726