From f94d8c661d3041e36d2cbdb6db1411ee42daab8e Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 15 Aug 2025 16:26:51 -0700 Subject: [PATCH] privileged_daemon: Log only to journal and not console - This prevents double logging for all log statements in privileged daemon. - Also drop conditional checking for systemd.journal python module. We hard depend on python3-systemd package which has it. Tests: - All logs messages from privileged daemon log only once to the journal. - For main service, the log message happens on console only when running on the command line. When the systemd service is started, it is only logged to the journal. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Joseph Nuthalapati --- plinth/log.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/plinth/log.py b/plinth/log.py index 69199c5d2..8f4fe4682 100644 --- a/plinth/log.py +++ b/plinth/log.py @@ -3,7 +3,6 @@ Setup logging for the application. """ -import importlib import logging import logging.config import warnings @@ -77,7 +76,8 @@ def action_init(): _capture_warnings() configuration = get_configuration() - del configuration['handlers']['console']['formatter'] + # Don't log to console + configuration['root']['handlers'] = ['journal'] logging.config.dictConfig(configuration) @@ -118,10 +118,13 @@ def get_configuration(): 'console': { 'class': 'logging.StreamHandler', 'formatter': 'color' + }, + 'journal': { + 'class': 'systemd.journal.JournalHandler' } }, 'root': { - 'handlers': ['console'], + 'handlers': ['console', 'journal'], 'level': default_level or ('DEBUG' if cfg.develop else 'INFO') }, 'loggers': { @@ -134,14 +137,4 @@ def get_configuration(): } } - try: - importlib.import_module('systemd.journal') - except ModuleNotFoundError: - pass - else: - configuration['handlers']['journal'] = { - 'class': 'systemd.journal.JournalHandler' - } - configuration['root']['handlers'].append('journal') - return configuration