From: Michael Tremer Date: Fri, 16 Sep 2022 13:33:56 +0000 (+0000) Subject: logger: Add debug switch X-Git-Tag: 0.9.28~303 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55f0f68d350b46e96a9635c6cff602fa8ed56594;p=pakfire.git logger: Add debug switch The setup function for the logger now has a debug switch to enable debug messages which will be sent to syslog only and not be printed to the console. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index 550cc7e4a..dfa0e54e5 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -28,9 +28,9 @@ class Daemon(object): # Setup logger self.log = logger.setup( "pakfire.daemon", - level=logging.DEBUG if self.debug else logging.INFO, syslog_identifier="pakfire-daemon", enable_console=self.verbose, + debug=self.debug, ) # Connect to the Pakfire Hub diff --git a/src/pakfire/logger.py b/src/pakfire/logger.py index 143755940..c20b077b1 100644 --- a/src/pakfire/logger.py +++ b/src/pakfire/logger.py @@ -24,7 +24,13 @@ import sys import systemd.journal import time -def setup(name, level=logging.INFO, syslog_identifier="pakfire", enable_console=True): +def setup(name, syslog_identifier="pakfire", enable_console=True, debug=False): + level = logging.INFO + + # Enable debug logging + if debug: + level = logging.DEBUG + log = logging.getLogger(name) log.setLevel(level) @@ -39,6 +45,9 @@ def setup(name, level=logging.INFO, syslog_identifier="pakfire", enable_console= console = ConsoleHandler() log.addHandler(console) + # Do not send any debug output to the console + console.setLevel(logging.INFO) + # Enable logging to journald journal = systemd.journal.JournalHandler( SYSLOG_IDENTIFIER=syslog_identifier, diff --git a/src/scripts/pakfire-builder.in b/src/scripts/pakfire-builder.in index a1256a6bb..4aa408ab2 100644 --- a/src/scripts/pakfire-builder.in +++ b/src/scripts/pakfire-builder.in @@ -41,6 +41,8 @@ class Cli(object): # Add arguments parser.add_argument("--arch", "-a", nargs="?", help=_("Run pakfire for the given architecture")) + parser.add_argument("--debug", action="store_true", + help=_("Enable debug mode")) parser.add_argument("--distro", nargs="?", default="ipfire3", # XXX for now help=_("Choose the distribution configuration to use for build")) parser.add_argument("--disable-snapshot", action="store_true", @@ -148,6 +150,7 @@ class Cli(object): "pakfire.builder.cli", syslog_identifier="pakfire-builder", enable_console=True, + debug=ns.debug, ) return pakfire.Pakfire(arch=ns.arch, conf=conf, logger=logger.log)