From 8168d10ea683d939ae52a1ed3d7c697c92bfae3d Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Thu, 9 Jun 2011 16:50:49 +0100 Subject: [PATCH] Issue #12168: SysLogHandler now allows NUL termination to be controlled using a new 'append_nul' attribute on the handler. --- Lib/logging/handlers.py | 6 +++++- Misc/NEWS | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 306cf86698..4a6b959946 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 15ed46f8e0..c5d2cec19a 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. -- 2.40.0