From: Vinay Sajip Date: Thu, 9 Jun 2011 15:50:49 +0000 (+0100) Subject: Issue #12168: SysLogHandler now allows NUL termination to be controlled using a new... X-Git-Tag: v3.3.0a1~2149^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8168d10ea683d939ae52a1ed3d7c697c92bfae3d;p=thirdparty%2FPython%2Fcpython.git Issue #12168: SysLogHandler now allows NUL termination to be controlled using a new 'append_nul' attribute on the handler. --- diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 306cf866983a..4a6b95994638 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -766,6 +766,8 @@ class SysLogHandler(logging.Handler): """ return self.priority_map.get(levelName, "warning") + append_nul = True # some old syslog daemons expect a NUL terminator + def emit(self, record): """ Emit a record. @@ -773,7 +775,9 @@ class SysLogHandler(logging.Handler): The record is formatted, and then sent to the syslog server. If exception information is present, it is NOT sent to the server. """ - msg = self.format(record) + '\000' + msg = self.format(record) + if self.append_nul: + msg += '\000' """ We need to convert record level to lowercase, maybe this will change in the future. diff --git a/Misc/NEWS b/Misc/NEWS index 15ed46f8e0bd..c5d2cec19a74 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Core and Builtins Library ------- +- Issue #12168: SysLogHandler now allows NUL termination to be controlled using + a new 'append_nul' attribute on the handler. + - Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes instead of os.stat.