|
|
8c93e6 |
From 9d19491f52cad798ce995f3f8d1c13e2dc54cb0c Mon Sep 17 00:00:00 2001
|
|
|
8c93e6 |
From: Marek Blaha <mblaha@redhat.com>
|
|
|
8c93e6 |
Date: Sun, 12 Jan 2020 15:52:16 +0100
|
|
|
8c93e6 |
Subject: [PATCH 1/2] Split loggers setup so that file loggers could be set
|
|
|
8c93e6 |
separately
|
|
|
8c93e6 |
|
|
|
8c93e6 |
---
|
|
|
8c93e6 |
dnf/logging.py | 46 +++++++++++++++++++++++++++++++---------------
|
|
|
8c93e6 |
1 file changed, 31 insertions(+), 15 deletions(-)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
diff --git a/dnf/logging.py b/dnf/logging.py
|
|
|
8c93e6 |
index df355efa57..bd660470a3 100644
|
|
|
8c93e6 |
--- a/dnf/logging.py
|
|
|
8c93e6 |
+++ b/dnf/logging.py
|
|
|
8c93e6 |
@@ -132,12 +132,14 @@ def _paint_mark(logger):
|
|
|
8c93e6 |
class Logging(object):
|
|
|
8c93e6 |
def __init__(self):
|
|
|
8c93e6 |
self.stdout_handler = self.stderr_handler = None
|
|
|
8c93e6 |
-
|
|
|
8c93e6 |
- @only_once
|
|
|
8c93e6 |
- def _presetup(self):
|
|
|
8c93e6 |
logging.addLevelName(DDEBUG, "DDEBUG")
|
|
|
8c93e6 |
logging.addLevelName(SUBDEBUG, "SUBDEBUG")
|
|
|
8c93e6 |
logging.addLevelName(TRACE, "TRACE")
|
|
|
8c93e6 |
+ logging.captureWarnings(True)
|
|
|
8c93e6 |
+ logging.raiseExceptions = False
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ @only_once
|
|
|
8c93e6 |
+ def _presetup(self):
|
|
|
8c93e6 |
logger_dnf = logging.getLogger("dnf")
|
|
|
8c93e6 |
logger_dnf.setLevel(TRACE)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
@@ -155,24 +157,19 @@ def _presetup(self):
|
|
|
8c93e6 |
self.stderr_handler = stderr
|
|
|
8c93e6 |
|
|
|
8c93e6 |
@only_once
|
|
|
8c93e6 |
- def _setup(self, verbose_level, error_level, logdir, log_size, log_rotate):
|
|
|
8c93e6 |
- self._presetup()
|
|
|
8c93e6 |
+ def _setup_file_loggers(self, verbose_level, logdir, log_size, log_rotate):
|
|
|
8c93e6 |
logger_dnf = logging.getLogger("dnf")
|
|
|
8c93e6 |
+ logger_dnf.setLevel(TRACE)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
# setup file logger
|
|
|
8c93e6 |
logfile = os.path.join(logdir, dnf.const.LOG)
|
|
|
8c93e6 |
handler = _create_filehandler(logfile, log_size, log_rotate)
|
|
|
8c93e6 |
logger_dnf.addHandler(handler)
|
|
|
8c93e6 |
- # temporarily turn off stdout/stderr handlers:
|
|
|
8c93e6 |
- self.stdout_handler.setLevel(SUPERCRITICAL)
|
|
|
8c93e6 |
- self.stderr_handler.setLevel(SUPERCRITICAL)
|
|
|
8c93e6 |
# put the marker in the file now:
|
|
|
8c93e6 |
_paint_mark(logger_dnf)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
# setup Python warnings
|
|
|
8c93e6 |
- logging.captureWarnings(True)
|
|
|
8c93e6 |
logger_warnings = logging.getLogger("py.warnings")
|
|
|
8c93e6 |
- logger_warnings.addHandler(self.stderr_handler)
|
|
|
8c93e6 |
logger_warnings.addHandler(handler)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
lr_logfile = os.path.join(logdir, dnf.const.LOG_LIBREPO)
|
|
|
8c93e6 |
@@ -184,22 +181,41 @@ def _setup(self, verbose_level, error_level, logdir, log_size, log_rotate):
|
|
|
8c93e6 |
logger_rpm.setLevel(SUBDEBUG)
|
|
|
8c93e6 |
logfile = os.path.join(logdir, dnf.const.LOG_RPM)
|
|
|
8c93e6 |
handler = _create_filehandler(logfile, log_size, log_rotate)
|
|
|
8c93e6 |
- logger_rpm.addHandler(self.stdout_handler)
|
|
|
8c93e6 |
- logger_rpm.addHandler(self.stderr_handler)
|
|
|
8c93e6 |
logger_rpm.addHandler(handler)
|
|
|
8c93e6 |
_paint_mark(logger_rpm)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ @only_once
|
|
|
8c93e6 |
+ def _setup(self, verbose_level, error_level, logdir, log_size, log_rotate):
|
|
|
8c93e6 |
+ self._presetup()
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ # temporarily turn off stdout/stderr handlers:
|
|
|
8c93e6 |
+ self.stdout_handler.setLevel(SUPERCRITICAL)
|
|
|
8c93e6 |
+ self.stderr_handler.setLevel(SUPERCRITICAL)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ self._setup_file_loggers(verbose_level, logdir, log_size, log_rotate)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ logger_warnings = logging.getLogger("py.warnings")
|
|
|
8c93e6 |
+ logger_warnings.addHandler(self.stderr_handler)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
+ # setup RPM callbacks logger
|
|
|
8c93e6 |
+ logger_rpm = logging.getLogger("dnf.rpm")
|
|
|
8c93e6 |
+ logger_rpm.addHandler(self.stdout_handler)
|
|
|
8c93e6 |
+ logger_rpm.addHandler(self.stderr_handler)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
# bring std handlers to the preferred level
|
|
|
8c93e6 |
self.stdout_handler.setLevel(verbose_level)
|
|
|
8c93e6 |
self.stderr_handler.setLevel(error_level)
|
|
|
8c93e6 |
- logging.raiseExceptions = False
|
|
|
8c93e6 |
|
|
|
8c93e6 |
- def _setup_from_dnf_conf(self, conf):
|
|
|
8c93e6 |
+ def _setup_from_dnf_conf(self, conf, file_loggers_only=False):
|
|
|
8c93e6 |
verbose_level_r = _cfg_verbose_val2level(conf.debuglevel)
|
|
|
8c93e6 |
error_level_r = _cfg_err_val2level(conf.errorlevel)
|
|
|
8c93e6 |
logdir = conf.logdir
|
|
|
8c93e6 |
log_size = conf.log_size
|
|
|
8c93e6 |
log_rotate = conf.log_rotate
|
|
|
8c93e6 |
- return self._setup(verbose_level_r, error_level_r, logdir, log_size, log_rotate)
|
|
|
8c93e6 |
+ if file_loggers_only:
|
|
|
8c93e6 |
+ return self._setup_file_loggers(verbose_level_r, logdir, log_size, log_rotate)
|
|
|
8c93e6 |
+ else:
|
|
|
8c93e6 |
+ return self._setup(verbose_level_r, error_level_r, logdir, log_size, log_rotate)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
|
|
|
8c93e6 |
class Timer(object):
|
|
|
8c93e6 |
|
|
|
8c93e6 |
From e43eaba4148446523eaf3e8ff1549c7576d00f1c Mon Sep 17 00:00:00 2001
|
|
|
8c93e6 |
From: Marek Blaha <mblaha@redhat.com>
|
|
|
8c93e6 |
Date: Sun, 12 Jan 2020 15:53:09 +0100
|
|
|
8c93e6 |
Subject: [PATCH 2/2] New API function base.setup_loggers() (RhBug:1788212)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
Gives API users ability to setup DNF loggers.
|
|
|
8c93e6 |
|
|
|
8c93e6 |
https://bugzilla.redhat.com/show_bug.cgi?id=1788212
|
|
|
8c93e6 |
---
|
|
|
8c93e6 |
dnf/base.py | 8 ++++++++
|
|
|
8c93e6 |
1 file changed, 8 insertions(+)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
diff --git a/dnf/base.py b/dnf/base.py
|
|
|
8c93e6 |
index b2c17bba30..56a9dfb478 100644
|
|
|
8c93e6 |
--- a/dnf/base.py
|
|
|
8c93e6 |
+++ b/dnf/base.py
|
|
|
8c93e6 |
@@ -2536,6 +2536,14 @@ def _raise_package_not_installed_error(self, pkg_spec, forms, reponame):
|
|
|
8c93e6 |
msg = _('All matches were filtered out by exclude filtering for argument')
|
|
|
8c93e6 |
raise dnf.exceptions.PackagesNotInstalledError(msg, pkg_spec)
|
|
|
8c93e6 |
|
|
|
8c93e6 |
+ def setup_loggers(self):
|
|
|
8c93e6 |
+ # :api
|
|
|
8c93e6 |
+ """
|
|
|
8c93e6 |
+ Setup DNF file loggers based on given configuration file. The loggers are set the same
|
|
|
8c93e6 |
+ way as if DNF was run from CLI.
|
|
|
8c93e6 |
+ """
|
|
|
8c93e6 |
+ self._logging._setup_from_dnf_conf(self.conf, file_loggers_only=True)
|
|
|
8c93e6 |
+
|
|
|
8c93e6 |
|
|
|
8c93e6 |
def _msg_installed(pkg):
|
|
|
8c93e6 |
name = ucd(pkg)
|