mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
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 <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
parent
0c6f04b55f
commit
f94d8c661d
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user