File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed
Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -769,14 +769,18 @@ def mapPriority(self, levelName):
769769 """
770770 return self .priority_map .get (levelName , "warning" )
771771
772+ append_nul = True # some old syslog daemons expect a NUL terminator
773+
772774 def emit (self , record ):
773775 """
774776 Emit a record.
775777
776778 The record is formatted, and then sent to the syslog server. If
777779 exception information is present, it is NOT sent to the server.
778780 """
779- msg = self .format (record ) + '\000 '
781+ msg = self .format (record )
782+ if self .append_nul :
783+ msg += '\000 '
780784 """
781785 We need to convert record level to lowercase, maybe this will
782786 change in the future.
Original file line number Diff line number Diff line change @@ -1399,8 +1399,7 @@ def setUp(self):
13991399 pointing to that server's address and port."""
14001400 BaseTest .setUp (self )
14011401 addr = ('localhost' , 0 )
1402- self .server = server = TestUDPServer (addr , self .handle_datagram ,
1403- 0.01 )
1402+ self .server = server = TestUDPServer (addr , self .handle_datagram , 0.01 )
14041403 server .start ()
14051404 server .ready .wait ()
14061405 self .sock_hdlr = logging .handlers .DatagramHandler ('localhost' ,
@@ -1478,6 +1477,11 @@ def test_output(self):
14781477 logger .error ("sp\xe4 m" )
14791478 self .handled .wait ()
14801479 self .assertEqual (self .log_output , b'<11>\xef \xbb \xbf sp\xc3 \xa4 m\x00 ' )
1480+ self .handled .clear ()
1481+ self .sl_hdlr .append_nul = False
1482+ logger .error ("sp\xe4 m" )
1483+ self .handled .wait ()
1484+ self .assertEqual (self .log_output , b'<11>\xef \xbb \xbf sp\xc3 \xa4 m' )
14811485
14821486
14831487@unittest .skipUnless (threading , 'Threading required for this test.' )
Original file line number Diff line number Diff line change @@ -187,6 +187,9 @@ Core and Builtins
187187Library
188188-------
189189
190+ - Issue #12168: SysLogHandler now allows NUL termination to be controlled using
191+ a new 'append_nul' attribute on the handler.
192+
190193- Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes
191194 instead of os.stat.
192195
You can’t perform that action at this time.
0 commit comments