Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@Zheaoli
Copy link
Contributor

@Zheaoli Zheaoli commented Jan 12, 2019

Copy link

@remilapeyre remilapeyre left a 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?

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 13, 2019

@remilapeyre
sorry about the fail.

I have already fixed the test error! This PR could be reviewed and merged right now.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 13, 2019

this PR needs backport to 3.0-3.7 and 2.7

@vsajip vsajip changed the title bpo-35726:QueueHandler formating affects other handlers bpo-35726:QueueHandler formatting affects other handlers Jan 13, 2019
Lib/logging/handlers.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 13, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

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.
@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 14, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@vsajip: please review the changes made to this pull request.

@vsajip vsajip merged commit da6424e into python:master Jan 23, 2019
@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 23, 2019

@vsajip this PR need be back to Python 3.5/3.6/3.7

@tirkarthi
Copy link
Member

3.5 and 3.6 are in security fixes only mode so this can be backported only to 3.7.

@Zheaoli
Copy link
Contributor Author

Zheaoli commented Jan 23, 2019

@tirkarthi Got it, thx

@tirkarthi
Copy link
Member

@Zheaoli @vsajip I am just curious if there is a test for this in test_logging or as a separate PR? I hope below script illustrates the issue.

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

@tirkarthi
Copy link
Member

tirkarthi commented Jan 23, 2019

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")
  • Without patch
./python.exe -m unittest -v test.test_logging.QueueHandlerTest.test_queue_listener_with_multiple_handlers
test_queue_listener_with_multiple_handlers (test.test_logging.QueueHandlerTest) ... FAIL

======================================================================
FAIL: test_queue_listener_with_multiple_handlers (test.test_logging.QueueHandlerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_logging.py", line 3519, in test_queue_listener_with_multiple_handlers
    self.assertEqual(self.stream.getvalue().strip(), "que -> ERROR: error")
AssertionError: 'que -> ERROR: que -> ERROR: error' != 'que -> ERROR: error'
- que -> ERROR: que -> ERROR: error
+ que -> ERROR: error


----------------------------------------------------------------------
Ran 1 test in 0.009s

FAILED (failures=1)
  • With patch
./python.exe -m unittest -v test.test_logging.QueueHandlerTest.test_queue_listener_with_multiple_handlers
test_queue_listener_with_multiple_handlers (test.test_logging.QueueHandlerTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.005s

OK

@vsajip
Copy link
Member

vsajip commented Jan 23, 2019

A PR with a test would be good, thanks. I don't believe there was a test for this specific case.

@miss-islington
Copy link
Contributor

Thanks @Zheaoli for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

tirkarthi pushed a commit to tirkarthi/cpython that referenced this pull request Apr 7, 2019
…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 <lizheao940510@gmail.com>
@bedevere-bot
Copy link

GH-12716 is a backport of this pull request to the 3.7 branch.

ned-deily pushed a commit that referenced this pull request May 2, 2019
…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 <lizheao940510@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.