From f36753fcb8c41170bf5e56ad8fc68a795fac4b7f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 20 Dec 2018 14:44:11 -0800 Subject: [PATCH] logging: Log to systemd journal directly While capturing stdout and stderr and automatically logging that to system logging daemon provides basic information, a lot of information lost in the process. This change logs to systemd journal directly so that rich information such as code file, code function, code line, etc, can be captured in a structured way. To avoid double logging, discard stdout and stderr in the systemd unit file. Reviewed-by: James Valleroy --- data/lib/systemd/system/plinth.service | 4 +++- debian/control | 1 + plinth/__main__.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/data/lib/systemd/system/plinth.service b/data/lib/systemd/system/plinth.service index dc17ab6b0..267d994ca 100644 --- a/data/lib/systemd/system/plinth.service +++ b/data/lib/systemd/system/plinth.service @@ -16,7 +16,7 @@ # [Unit] -Description=Plinth Web Interface +Description=FreedomBox Service (Plinth) Documentation=man:plinth(1) After=network.target @@ -26,6 +26,8 @@ Restart=on-failure ExecReload=/bin/kill -HUP $MAINPID User=plinth Group=plinth +StandardOutput=null +StandardError=null [Install] WantedBy=multi-user.target diff --git a/debian/control b/debian/control index 3e7bb9c85..1cde81985 100644 --- a/debian/control +++ b/debian/control @@ -38,6 +38,7 @@ Build-Depends: debhelper (>= 11~) , python3-setuptools-git , python3-yaml , xmlto +Recommends: python3-systemd Standards-Version: 4.2.1 Homepage: https://salsa.debian.org/freedombox-team/plinth Vcs-Git: https://salsa.debian.org/freedombox-team/plinth.git diff --git a/plinth/__main__.py b/plinth/__main__.py index 8e4ea3544..ec71646e6 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -176,6 +176,17 @@ def configure_django(): } } + try: + importlib.import_module('systemd.journal') + except ModuleNotFoundError: + pass + else: + logging_configuration['handlers']['journal'] = { + 'class': 'systemd.journal.JournalHandler' + } + logging_configuration['root']['handlers'].append('journal') + + templates = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates',