Commit c88009c4 authored by Georg Brandl's avatar Georg Brandl Committed by Georg Brandl
Browse files

systemd: hide tracebacks by default

The tracebacks in the log take a lot of space when just scrolling through
the syslog.  systemd allows packing that info into another field of the
journal, and by adding a catalog entry we allow this to be shown when
using `journalctl -x`.

Change-Id: I797e00bad0769cc045739909b76435a460a94869
Reviewed-on: https://forge.frm2.tum.de/review/c/frm2/tango/entangle/+/26158


Tested-by: default avatarJenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: default avatarEnrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: default avatarGeorg Brandl <g.brandl@fz-juelich.de>
parent f086ffbf
#!/bin/sh
set -e
journalctl --update-catalog
......@@ -274,6 +274,7 @@ class SimpleLogfileHandler(StreamHandler):
self.setFormatter(LogfileFormatter(LOGFMT, DATEFMT))
def _open(self):
# pylint: disable=consider-using-with
return open(self.baseFilename, self.mode)
def emit(self, record):
......@@ -324,6 +325,7 @@ class LogfileHandler(StreamHandler):
if hasattr(os, 'symlink'):
os.symlink(path.basename(self.baseFilename), self._currentsymlink)
# finally open the new logfile....
# pylint: disable=consider-using-with
return open(self.baseFilename, self.mode)
def emit(self, record):
......@@ -402,16 +404,24 @@ class JournalHandler(SystemdJournalHandler):
pri = self.mapPriority(record.levelno)
ident = 'entangle-server:%s' % self._instance
message = self.format(record)
send(
message,
PRIORITY=format(pri),
SYSLOG_IDENTIFIER=ident,
# this is necessary to avoid getting the location of
# emit() in every message
CODE_FILE='',
# we don't use self._extra since it would supply another
# SYSLOG_IDENTIFIER argument
)
message, _, tb = message.partition('\n')
if not tb:
send(
message,
PRIORITY=format(pri),
SYSLOG_IDENTIFIER=ident,
# this is necessary to avoid getting the location of
# emit() in every message
CODE_FILE='',
# we don't use self._extra since it would supply another
# SYSLOG_IDENTIFIER argument
)
else:
# same, but with our MESSAGE_ID set, so that the traceback
# is shown on request with journalctl -x
send(message, PRIORITY=format(pri), SYSLOG_IDENTIFIER=ident,
TRACEBACK=tb, CODE_FILE='',
MESSAGE_ID='dbd9cc2e14b5456db8b6dd2ee50c3e50')
except Exception:
self.handleError(record)
......
# systemd message catalog for Entangle
#
# All log entries with a traceback get this message-ID set.
# This leads to `journalctl -x` expanding the template below
# and showing the traceback, while `journalctl` ignores it.
-- dbd9cc2e14b5456db8b6dd2ee50c3e50
@TRACEBACK@
......@@ -47,6 +47,7 @@ setup(
'etc/entangle.target',
'etc/entangle-late-generator.service']),
('/lib/systemd/scripts', ['etc/entangle-late-generator']),
('/usr/lib/systemd/catalog', ['etc/entangle.catalog']),
('/var/log/entangle', []),
('/var/run/entangle', []),
],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment