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
2353e355
Commit
2353e355
authored
Jun 27, 2011
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #12419: Added ident to SysLogHandler.
parent
345a5d73
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Doc/library/logging.handlers.rst
Doc/library/logging.handlers.rst
+9
-0
Lib/logging/handlers.py
Lib/logging/handlers.py
+3
-0
Lib/test/test_logging.py
Lib/test/test_logging.py
+5
-0
No files found.
Doc/library/logging.handlers.rst
View file @
2353e355
...
...
@@ -452,6 +452,15 @@ supports sending logging messages to a remote or local Unix syslog.
behaviour) but can be set to ``False`` on a ``SysLogHandler`` instance
in order for that instance to *not* append the NUL terminator.
.. versionchanged:: 3.3
(See: :issue:`12419`.) In earlier versions, there was no facility for
an "ident" or "tag" prefix to identify the source of the message. This
can now be specified using a class-level attribute, defaulting to
``""`` to preserve existing behaviour, but which can be overridden on
a ``SysLogHandler`` instance in order for that instance to prepend
the ident to every message handled. Note that the provided ident must
be text, not bytes, and is prepended to the message exactly as is.
.. method:: encodePriority(facility, priority)
Encodes the facility and priority into an integer. You can pass in strings
...
...
Lib/logging/handlers.py
View file @
2353e355
...
...
@@ -769,6 +769,7 @@ class SysLogHandler(logging.Handler):
"""
return
self
.
priority_map
.
get
(
levelName
,
"warning"
)
ident
=
''
# prepended to all messages
append_nul
=
True
# some old syslog daemons expect a NUL terminator
def
emit
(
self
,
record
):
...
...
@@ -779,6 +780,8 @@ class SysLogHandler(logging.Handler):
exception information is present, it is NOT sent to the server.
"""
msg
=
self
.
format
(
record
)
if
self
.
ident
:
msg
=
self
.
ident
+
msg
if
self
.
append_nul
:
msg
+=
'
\
000
'
"""
...
...
Lib/test/test_logging.py
View file @
2353e355
...
...
@@ -1482,6 +1482,11 @@ class SysLogHandlerTest(BaseTest):
logger.error("
sp
\
xe4m
")
self.handled.wait()
self.assertEqual(self.log_output, b'<11>
\
xef
\
xbb
\
xbf
sp
\
xc3
\
xa4
m')
self.handled.clear()
self.sl_hdlr.ident = "
h
\
xe4m
-
"
logger.error("
sp
\
xe4m
")
self.handled.wait()
self.assertEqual(self.log_output, b'<11>
\
xef
\
xbb
\
xbf
h
\
xc3
\
xa4
m-sp
\
xc3
\
xa4
m')
@unittest.skipUnless(threading, 'Threading required for this test.')
...
...
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