Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
adfe3440
Commit
adfe3440
authored
Aug 01, 2017
by
favll
Committed by
Vinay Sajip
Aug 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31084: QueueHandler now formats messages correctly. (GH-2954)
parent
6f446bee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
Lib/logging/handlers.py
Lib/logging/handlers.py
+5
-4
Lib/test/test_logging.py
Lib/test/test_logging.py
+14
-0
No files found.
Lib/logging/handlers.py
View file @
adfe3440
...
...
@@ -1372,13 +1372,14 @@ class QueueHandler(logging.Handler):
of the record while leaving the original intact.
"""
# The format operation gets traceback text into record.exc_text
# (if there's exception data), and also
puts the message into
#
record.
message. We can then use this to replace the original
# (if there's exception data), and also
returns the formatted
# message. We can then use this to replace the original
# msg + args, as these might be unpickleable. We also zap the
# exc_info attribute, as it's no longer needed and, if not None,
# will typically not be pickleable.
self
.
format
(
record
)
record
.
msg
=
record
.
message
msg
=
self
.
format
(
record
)
record
.
message
=
msg
record
.
msg
=
msg
record
.
args
=
None
record
.
exc_info
=
None
return
record
...
...
Lib/test/test_logging.py
View file @
adfe3440
...
...
@@ -3126,6 +3126,7 @@ class QueueHandlerTest(BaseTest):
BaseTest.setUp(self)
self.queue = queue.Queue(-1)
self.que_hdlr = logging.handlers.QueueHandler(self.queue)
self.name = 'que'
self.que_logger = logging.getLogger('que')
self.que_logger.propagate = False
self.que_logger.setLevel(logging.WARNING)
...
...
@@ -3147,6 +3148,19 @@ class QueueHandlerTest(BaseTest):
self.assertEqual(data.name, self.que_logger.name)
self.assertEqual((data.msg, data.args), (msg, None))
def test_formatting(self):
msg = self.next_message()
levelname = logging.getLevelName(logging.WARNING)
log_format_str = '{name} -> {levelname}: {message}'
formatted_msg = log_format_str.format(name=self.name,
levelname=levelname, message=msg)
formatter = logging.Formatter(self.log_format)
self.que_hdlr.setFormatter(formatter)
self.que_logger.warning(msg)
log_record = self.queue.get_nowait()
self.assertEqual(formatted_msg, log_record.msg)
self.assertEqual(formatted_msg, log_record.message)
@unittest.skipUnless(hasattr(logging.handlers, 'QueueListener'),
'logging.handlers.QueueListener required for this test')
def test_queue_listener(self):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment