From 7c8b63f69b9348334da3344925f9c092ee850859 Mon Sep 17 00:00:00 2001 From: reahaas Date: Wed, 17 Feb 2021 17:25:44 +0200 Subject: [PATCH 1/2] Update handlers.py SyslogHandler, emit function add the nul_character to the message. This PR allows the user to choose what character to use to separate messages. The functionality of `append_nul` that was a boolean variable stays the same since the user can override this value since it's a class attribute: From the docs: ``` To enable easier handling of Syslog messages in the face of all these differing daemon behaviours, the appending of the NUL byte has been made configurable, through the use of a class-level attribute, append_nul. This defaults to True (preserving the existing behaviour) but can be set to False on a SysLogHandler instance in order for that instance to not append the NUL terminator. ``` So now this functionality is possible through setting: ``` message_separator_character = '' # using the empty string # instead of doing: # append_nul = False ``` --- Lib/logging/handlers.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 867ef4ebc7600a0..e3426a3911ea6b4 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -923,8 +923,8 @@ def mapPriority(self, levelName): """ return self.priority_map.get(levelName, "warning") - ident = '' # prepended to all messages - append_nul = True # some old syslog daemons expect a NUL terminator + ident = '' # prepended to all messages + message_separator_character = '\000' # some old syslog daemons expect a NUL terminator def emit(self, record): """ @@ -937,8 +937,7 @@ def emit(self, record): msg = self.format(record) if self.ident: msg = self.ident + msg - if self.append_nul: - msg += '\000' + msg += message_separator_character # We need to convert record level to lowercase, maybe this will # change in the future. From f5ac76cbc62f8fedd8b73c49e425a610a3b17405 Mon Sep 17 00:00:00 2001 From: reahaas Date: Wed, 17 Feb 2021 17:39:08 +0200 Subject: [PATCH 2/2] Update handlers.py Better concatenating of the message_separator_character to the msg. --- Lib/logging/handlers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index e3426a3911ea6b4..2de1008e83fb3f7 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -934,10 +934,9 @@ def emit(self, record): exception information is present, it is NOT sent to the server. """ try: - msg = self.format(record) + msg = self.format(record) + message_separator_character if self.ident: msg = self.ident + msg - msg += message_separator_character # We need to convert record level to lowercase, maybe this will # change in the future.