richardphibel / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

Blame SOURCES/0002-Add-logfilelevel-configuration-RhBug-1802074.patch

e043d7
From 9f9bfdfcb576846436f97275d6ee82004ceb4cb9 Mon Sep 17 00:00:00 2001
e043d7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
e043d7
Date: Thu, 4 Jun 2020 16:02:58 +0200
e043d7
Subject: [PATCH 1/3] Add logfilelevel configuration (RhBug:1802074)
e043d7
e043d7
https://bugzilla.redhat.com/show_bug.cgi?id=1802074
e043d7
---
e043d7
 dnf.spec         |  2 +-
e043d7
 dnf/logging.py   | 17 +++++++++++------
e043d7
 doc/conf_ref.rst |  6 ++++++
e043d7
 3 files changed, 18 insertions(+), 7 deletions(-)
e043d7
e043d7
diff --git a/dnf.spec b/dnf.spec
e043d7
index 1423c6d5b5..27bae7aaa7 100644
e043d7
--- a/dnf.spec
e043d7
+++ b/dnf.spec
e043d7
@@ -1,5 +1,5 @@
e043d7
 # default dependencies
e043d7
-%global hawkey_version 0.48.0
e043d7
+%global hawkey_version 0.50.0
e043d7
 %global libcomps_version 0.1.8
e043d7
 %global libmodulemd_version 1.4.0
e043d7
 %global rpm_version 4.14.0
e043d7
diff --git a/dnf/logging.py b/dnf/logging.py
e043d7
index bd660470a3..c578575e1c 100644
e043d7
--- a/dnf/logging.py
e043d7
+++ b/dnf/logging.py
e043d7
@@ -70,11 +70,14 @@ def filter(self, record):
e043d7
     4 : logging.DEBUG,
e043d7
     5 : logging.DEBUG,
e043d7
     6 : logging.DEBUG, # verbose value
e043d7
+    7 : DDEBUG,
e043d7
+    8 : SUBDEBUG,
e043d7
+    9 : TRACE,
e043d7
     }
e043d7
 
e043d7
 def _cfg_verbose_val2level(cfg_errval):
e043d7
     assert 0 <= cfg_errval <= 10
e043d7
-    return _VERBOSE_VAL_MAPPING.get(cfg_errval, DDEBUG)
e043d7
+    return _VERBOSE_VAL_MAPPING.get(cfg_errval, TRACE)
e043d7
 
e043d7
 
e043d7
 # Both the DNF default and the verbose default are WARNING. Note that ERROR has
e043d7
@@ -157,13 +160,14 @@ def _presetup(self):
e043d7
         self.stderr_handler = stderr
e043d7
 
e043d7
     @only_once
e043d7
-    def _setup_file_loggers(self, verbose_level, logdir, log_size, log_rotate):
e043d7
+    def _setup_file_loggers(self, logfile_level, verbose_level, logdir, log_size, log_rotate):
e043d7
         logger_dnf = logging.getLogger("dnf")
e043d7
         logger_dnf.setLevel(TRACE)
e043d7
 
e043d7
         # setup file logger
e043d7
         logfile = os.path.join(logdir, dnf.const.LOG)
e043d7
         handler = _create_filehandler(logfile, log_size, log_rotate)
e043d7
+        handler.setLevel(logfile_level)
e043d7
         logger_dnf.addHandler(handler)
e043d7
         # put the marker in the file now:
e043d7
         _paint_mark(logger_dnf)
e043d7
@@ -185,14 +189,14 @@ def _setup_file_loggers(self, verbose_level, logdir, log_size, log_rotate):
e043d7
         _paint_mark(logger_rpm)
e043d7
 
e043d7
     @only_once
e043d7
-    def _setup(self, verbose_level, error_level, logdir, log_size, log_rotate):
e043d7
+    def _setup(self, verbose_level, error_level, logfile_level, logdir, log_size, log_rotate):
e043d7
         self._presetup()
e043d7
 
e043d7
         # temporarily turn off stdout/stderr handlers:
e043d7
         self.stdout_handler.setLevel(SUPERCRITICAL)
e043d7
         self.stderr_handler.setLevel(SUPERCRITICAL)
e043d7
 
e043d7
-        self._setup_file_loggers(verbose_level, logdir, log_size, log_rotate)
e043d7
+        self._setup_file_loggers(logfile_level, verbose_level, logdir, log_size, log_rotate)
e043d7
 
e043d7
         logger_warnings = logging.getLogger("py.warnings")
e043d7
         logger_warnings.addHandler(self.stderr_handler)
e043d7
@@ -209,13 +213,14 @@ def _setup(self, verbose_level, error_level, logdir, log_size, log_rotate):
e043d7
     def _setup_from_dnf_conf(self, conf, file_loggers_only=False):
e043d7
         verbose_level_r = _cfg_verbose_val2level(conf.debuglevel)
e043d7
         error_level_r = _cfg_err_val2level(conf.errorlevel)
e043d7
+        logfile_level_r = _cfg_verbose_val2level(conf.logfilelevel)
e043d7
         logdir = conf.logdir
e043d7
         log_size = conf.log_size
e043d7
         log_rotate = conf.log_rotate
e043d7
         if file_loggers_only:
e043d7
-            return self._setup_file_loggers(verbose_level_r, logdir, log_size, log_rotate)
e043d7
+            return self._setup_file_loggers(logfile_level_r, verbose_level_r, logdir, log_size, log_rotate)
e043d7
         else:
e043d7
-            return self._setup(verbose_level_r, error_level_r, logdir, log_size, log_rotate)
e043d7
+            return self._setup(verbose_level_r, error_level_r, logfile_level_r, logdir, log_size, log_rotate)
e043d7
 
e043d7
 
e043d7
 class Timer(object):
e043d7
diff --git a/doc/conf_ref.rst b/doc/conf_ref.rst
e043d7
index cf442770c9..fed6efcec7 100644
e043d7
--- a/doc/conf_ref.rst
e043d7
+++ b/doc/conf_ref.rst
e043d7
@@ -268,6 +268,12 @@ configuration file by your distribution to override the DNF defaults.
e043d7
 
e043d7
     Directory where the log files will be stored. Default is ``/var/log``.
e043d7
 
e043d7
+``logfilelevel``
e043d7
+    :ref:`integer <integer-label>`
e043d7
+
e043d7
+    Log file messages output level, in the range 0 to 10. The higher the number the
e043d7
+    more debug output is put to logs. Default is 9.
e043d7
+
e043d7
 .. _log_rotate-label:
e043d7
 
e043d7
 ``log_rotate``
e043d7
e043d7
From 1233d7da657ffbd03f9ffc274b648da0bb2898bf Mon Sep 17 00:00:00 2001
e043d7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
e043d7
Date: Fri, 5 Jun 2020 09:21:15 +0200
e043d7
Subject: [PATCH 2/3] Update unit logging test to reflect logfilelevel addition
e043d7
e043d7
---
e043d7
 tests/test_logging.py | 16 +++++++++-------
e043d7
 1 file changed, 9 insertions(+), 7 deletions(-)
e043d7
e043d7
diff --git a/tests/test_logging.py b/tests/test_logging.py
e043d7
index a7fee3e67c..80e219d882 100644
e043d7
--- a/tests/test_logging.py
e043d7
+++ b/tests/test_logging.py
e043d7
@@ -88,7 +88,7 @@ def test_setup(self):
e043d7
         logger = logging.getLogger("dnf")
e043d7
         with tests.support.patch_std_streams() as (stdout, stderr):
e043d7
             self.logging._setup(
e043d7
-                logging.INFO, logging.ERROR, self.logdir, self.log_size, self.log_rotate)
e043d7
+                logging.INFO, logging.ERROR, dnf.logging.TRACE, self.logdir, self.log_size, self.log_rotate)
e043d7
             self._bench(logger)
e043d7
         self.assertEqual("i\n", stdout.getvalue())
e043d7
         self.assertEqual("e\n", stderr.getvalue())
e043d7
@@ -97,7 +97,7 @@ def test_setup_verbose(self):
e043d7
         logger = logging.getLogger("dnf")
e043d7
         with tests.support.patch_std_streams() as (stdout, stderr):
e043d7
             self.logging._setup(
e043d7
-                logging.DEBUG, logging.WARNING, self.logdir, self.log_size, self.log_rotate)
e043d7
+                logging.DEBUG, logging.WARNING, dnf.logging.TRACE, self.logdir, self.log_size, self.log_rotate)
e043d7
             self._bench(logger)
e043d7
         self.assertEqual("d\ni\n", stdout.getvalue())
e043d7
         self.assertEqual("w\ne\n", stderr.getvalue())
e043d7
@@ -105,20 +105,22 @@ def test_setup_verbose(self):
e043d7
     @mock.patch('dnf.logging.Logging._setup')
e043d7
     def test_setup_from_dnf_conf(self, setup_m):
e043d7
         conf = mock.Mock(
e043d7
-            debuglevel=2, errorlevel=3, logdir=self.logdir,
e043d7
+            debuglevel=2, errorlevel=3, logfilelevel=2, logdir=self.logdir,
e043d7
             log_size=self.log_size, log_rotate=self.log_rotate)
e043d7
         self.logging._setup_from_dnf_conf(conf)
e043d7
         self.assertEqual(setup_m.call_args, mock.call(dnf.logging.INFO,
e043d7
                                                       dnf.logging.WARNING,
e043d7
+                                                      dnf.logging.INFO,
e043d7
                                                       self.logdir,
e043d7
                                                       self.log_size,
e043d7
                                                       self.log_rotate))
e043d7
         conf = mock.Mock(
e043d7
-            debuglevel=6, errorlevel=6, logdir=self.logdir,
e043d7
+            debuglevel=6, errorlevel=6, logfilelevel=6, logdir=self.logdir,
e043d7
             log_size=self.log_size, log_rotate=self.log_rotate)
e043d7
         self.logging._setup_from_dnf_conf(conf)
e043d7
         self.assertEqual(setup_m.call_args, mock.call(dnf.logging.DEBUG,
e043d7
                                                       dnf.logging.WARNING,
e043d7
+                                                      dnf.logging.DEBUG,
e043d7
                                                       self.logdir,
e043d7
                                                       self.log_size,
e043d7
                                                       self.log_rotate))
e043d7
@@ -126,7 +128,7 @@ def test_setup_from_dnf_conf(self, setup_m):
e043d7
     def test_file_logging(self):
e043d7
         # log nothing to the console:
e043d7
         self.logging._setup(
e043d7
-            dnf.logging.SUPERCRITICAL, dnf.logging.SUPERCRITICAL,
e043d7
+            dnf.logging.SUPERCRITICAL, dnf.logging.SUPERCRITICAL, dnf.logging.TRACE,
e043d7
             self.logdir, self.log_size, self.log_rotate)
e043d7
         logger = logging.getLogger("dnf")
e043d7
         with tests.support.patch_std_streams() as (stdout, stderr):
e043d7
@@ -145,7 +147,7 @@ def test_file_logging(self):
e043d7
     def test_rpm_logging(self):
e043d7
         # log everything to the console:
e043d7
         self.logging._setup(
e043d7
-            dnf.logging.SUBDEBUG, dnf.logging.SUBDEBUG,
e043d7
+            dnf.logging.SUBDEBUG, dnf.logging.SUBDEBUG, dnf.logging.TRACE,
e043d7
             self.logdir, self.log_size, self.log_rotate)
e043d7
         logger = logging.getLogger("dnf.rpm")
e043d7
         with tests.support.patch_std_streams() as (stdout, stderr):
e043d7
@@ -167,7 +169,7 @@ def test_setup_only_once(self):
e043d7
         logger = logging.getLogger("dnf")
e043d7
         self.assertLength(logger.handlers, 0)
e043d7
         self.logging._setup(
e043d7
-            dnf.logging.SUBDEBUG, dnf.logging.SUBDEBUG,
e043d7
+            dnf.logging.SUBDEBUG, dnf.logging.SUBDEBUG, dnf.logging.TRACE,
e043d7
             self.logdir, self.log_size, self.log_rotate)
e043d7
         cnt = len(logger.handlers)
e043d7
         self.assertGreater(cnt, 0)
e043d7
e043d7
From 8a57da7229c67315d113b3c61cf981e1a7d81189 Mon Sep 17 00:00:00 2001
e043d7
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
e043d7
Date: Thu, 25 Jun 2020 14:03:02 +0200
e043d7
Subject: [PATCH 3/3] Control hawkey and librepo log verbosity with
e043d7
 logfilelevel
e043d7
e043d7
= changelog =
e043d7
msg: New config option 'logfilelevel' now controls logging to dnf.log, dnf.librepo.log and hawkey.log
e043d7
type: enhancement
e043d7
resolves: 1802074
e043d7
---
e043d7
 dnf/logging.py   | 11 +++++++----
e043d7
 dnf/sack.py      |  2 +-
e043d7
 doc/conf_ref.rst |  3 +++
e043d7
 3 files changed, 11 insertions(+), 5 deletions(-)
e043d7
e043d7
diff --git a/dnf/logging.py b/dnf/logging.py
e043d7
index c578575e1c..b5196988f7 100644
e043d7
--- a/dnf/logging.py
e043d7
+++ b/dnf/logging.py
e043d7
@@ -43,6 +43,7 @@
e043d7
 DDEBUG = 8  # used by anaconda (pyanaconda/payload/dnfpayload.py)
e043d7
 SUBDEBUG = 6
e043d7
 TRACE = 4
e043d7
+ALL = 2
e043d7
 
e043d7
 def only_once(func):
e043d7
     """Method decorator turning the method into noop on second or later calls."""
e043d7
@@ -73,6 +74,7 @@ def filter(self, record):
e043d7
     7 : DDEBUG,
e043d7
     8 : SUBDEBUG,
e043d7
     9 : TRACE,
e043d7
+    10: ALL,   # more verbous librepo and hawkey
e043d7
     }
e043d7
 
e043d7
 def _cfg_verbose_val2level(cfg_errval):
e043d7
@@ -138,6 +140,7 @@ def __init__(self):
e043d7
         logging.addLevelName(DDEBUG, "DDEBUG")
e043d7
         logging.addLevelName(SUBDEBUG, "SUBDEBUG")
e043d7
         logging.addLevelName(TRACE, "TRACE")
e043d7
+        logging.addLevelName(ALL, "ALL")
e043d7
         logging.captureWarnings(True)
e043d7
         logging.raiseExceptions = False
e043d7
 
e043d7
@@ -160,7 +163,7 @@ def _presetup(self):
e043d7
         self.stderr_handler = stderr
e043d7
 
e043d7
     @only_once
e043d7
-    def _setup_file_loggers(self, logfile_level, verbose_level, logdir, log_size, log_rotate):
e043d7
+    def _setup_file_loggers(self, logfile_level, logdir, log_size, log_rotate):
e043d7
         logger_dnf = logging.getLogger("dnf")
e043d7
         logger_dnf.setLevel(TRACE)
e043d7
 
e043d7
@@ -177,7 +180,7 @@ def _setup_file_loggers(self, logfile_level, verbose_level, logdir, log_size, lo
e043d7
         logger_warnings.addHandler(handler)
e043d7
 
e043d7
         lr_logfile = os.path.join(logdir, dnf.const.LOG_LIBREPO)
e043d7
-        libdnf.repo.LibrepoLog.addHandler(lr_logfile, verbose_level <= DEBUG)
e043d7
+        libdnf.repo.LibrepoLog.addHandler(lr_logfile, logfile_level <= ALL)
e043d7
 
e043d7
         # setup RPM callbacks logger
e043d7
         logger_rpm = logging.getLogger("dnf.rpm")
e043d7
@@ -196,7 +199,7 @@ def _setup(self, verbose_level, error_level, logfile_level, logdir, log_size, lo
e043d7
         self.stdout_handler.setLevel(SUPERCRITICAL)
e043d7
         self.stderr_handler.setLevel(SUPERCRITICAL)
e043d7
 
e043d7
-        self._setup_file_loggers(logfile_level, verbose_level, logdir, log_size, log_rotate)
e043d7
+        self._setup_file_loggers(logfile_level, logdir, log_size, log_rotate)
e043d7
 
e043d7
         logger_warnings = logging.getLogger("py.warnings")
e043d7
         logger_warnings.addHandler(self.stderr_handler)
e043d7
@@ -218,7 +221,7 @@ def _setup_from_dnf_conf(self, conf, file_loggers_only=False):
e043d7
         log_size = conf.log_size
e043d7
         log_rotate = conf.log_rotate
e043d7
         if file_loggers_only:
e043d7
-            return self._setup_file_loggers(logfile_level_r, verbose_level_r, logdir, log_size, log_rotate)
e043d7
+            return self._setup_file_loggers(logfile_level_r, logdir, log_size, log_rotate)
e043d7
         else:
e043d7
             return self._setup(verbose_level_r, error_level_r, logfile_level_r, logdir, log_size, log_rotate)
e043d7
 
e043d7
diff --git a/dnf/sack.py b/dnf/sack.py
e043d7
index fb8c70712f..3c6bc3bbe0 100644
e043d7
--- a/dnf/sack.py
e043d7
+++ b/dnf/sack.py
e043d7
@@ -53,7 +53,7 @@ def _build_sack(base):
e043d7
                 arch=base.conf.substitutions["arch"],
e043d7
                 cachedir=cachedir, rootdir=base.conf.installroot,
e043d7
                 logfile=os.path.join(base.conf.logdir, dnf.const.LOG_HAWKEY),
e043d7
-                logdebug=base.conf.debuglevel > 2)
e043d7
+                logdebug=base.conf.logfilelevel > 9)
e043d7
 
e043d7
 
e043d7
 def _rpmdb_sack(base):
e043d7
diff --git a/doc/conf_ref.rst b/doc/conf_ref.rst
e043d7
index fed6efcec7..fdb44a657d 100644
e043d7
--- a/doc/conf_ref.rst
e043d7
+++ b/doc/conf_ref.rst
e043d7
@@ -274,6 +274,9 @@ configuration file by your distribution to override the DNF defaults.
e043d7
     Log file messages output level, in the range 0 to 10. The higher the number the
e043d7
     more debug output is put to logs. Default is 9.
e043d7
 
e043d7
+    This option controls dnf.log, dnf.librepo.log and hawkey.log. Although dnf.librepo.log
e043d7
+    and hawkey.log are affected only by setting the logfilelevel to 10.
e043d7
+
e043d7
 .. _log_rotate-label:
e043d7
 
e043d7
 ``log_rotate``