[systemd-devel] [RFC PATCH] systemd-python: add SYSLOG_IDENTIFIER to JournalHandler

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Apr 22 13:31:47 PDT 2013


Otherwise, we get SYSLOG_IDENTIFIER=python or something
similar, which is completely useless.
---
Thoughts?

Specifically, I'm not sure if is worthwhile to allow overriding
SYSLOG_IDENTIFIER per message. Maybe this ability should be removed.

Zbyszek

 src/python-systemd/journal.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py
index 6c740b0..39db4bb 100644
--- a/src/python-systemd/journal.py
+++ b/src/python-systemd/journal.py
@@ -469,9 +469,15 @@ class JournalHandler(_logging.Handler):
         The following journal fields will be sent:
         `MESSAGE`, `PRIORITY`, `THREAD_NAME`, `CODE_FILE`, `CODE_LINE`,
         `CODE_FUNC`, `LOGGER` (name as supplied to getLogger call),
-        `MESSAGE_ID` (optional, see above).
+        `MESSAGE_ID` (optional, see above), `SYSLOG_IDENTIFIER` (optional).
         """
 
+        def __init__(self, level=_logging.NOTSET, SYSLOG_IDENTIFIER=None):
+                super(JournalHandler, self).__init__(level)
+                self._SYSLOG_IDENTIFIER = (_sys.argv[0]
+                                           if SYSLOG_IDENTIFIER is None
+                                           else SYSLOG_IDENTIFIER)
+
         def emit(self, record):
                 """Write record as journal event.
 
@@ -485,8 +491,11 @@ class JournalHandler(_logging.Handler):
                         msg = self.format(record)
                         pri = self.mapPriority(record.levelno)
                         mid = getattr(record, 'MESSAGE_ID', None)
+                        sid = getattr(record, 'SYSLOG_IDENTIFIER',
+                                              self._SYSLOG_IDENTIFIER)
                         send(msg,
                              MESSAGE_ID=mid,
+                             SYSLOG_IDENTIFIER=sid,
                              PRIORITY=format(pri),
                              LOGGER=record.name,
                              THREAD_NAME=record.threadName,
-- 
1.8.2



More information about the systemd-devel mailing list