From 208738dd32bbd16a50790d7ef726f70dc8080a95 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 5 Dec 2021 15:09:36 +0000 Subject: [PATCH] Enable logging to journald Signed-off-by: Michael Tremer --- Makefile.am | 1 + src/westferry/__init__.py | 1 + src/westferry/logging.py | 36 ++++++++++++++++++++++++++++++++++++ src/westferry/ui/forms.py | 3 +-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/westferry/logging.py diff --git a/Makefile.am b/Makefile.am index 53425ce..6db0a9a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,6 +86,7 @@ westferry_PYTHON = \ src/westferry/constants.py \ src/westferry/application.py \ src/westferry/i18n.py \ + src/westferry/logging.py \ src/westferry/services.py westferrydir = $(pythondir)/westferry diff --git a/src/westferry/__init__.py b/src/westferry/__init__.py index 9bd1ba1..9660f13 100644 --- a/src/westferry/__init__.py +++ b/src/westferry/__init__.py @@ -19,4 +19,5 @@ # # ############################################################################### +from . import logging from . import services diff --git a/src/westferry/logging.py b/src/westferry/logging.py new file mode 100644 index 0000000..337285d --- /dev/null +++ b/src/westferry/logging.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +############################################################################### +# # +# Westferry - The IPFire web user interface # +# Copyright (C) 2021 IPFire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import logging +import systemd.journal + +# Initialize root logger +log = logging.getLogger("westferry") +log.propagate = False + +# Set logger into DEBUG mode by default +log.setLevel(logging.DEBUG) + +# Enable logging to journald +journal = systemd.journal.JournalHandler( + SYSLOG_IDENTIFIER=__name__, +) +log.addHandler(journal) diff --git a/src/westferry/ui/forms.py b/src/westferry/ui/forms.py index abd8545..fca8adc 100644 --- a/src/westferry/ui/forms.py +++ b/src/westferry/ui/forms.py @@ -19,10 +19,9 @@ # # ############################################################################### -import logging - from . import base +import logging log = logging.getLogger(__name__) class Form(object): -- 2.47.3