Blame SOURCES/sos-bz1904045-preset-ignores-verbosity.patch

bffc8a
From 169898b47b26734a8cdcb748157f7314f7f8821b Mon Sep 17 00:00:00 2001
bffc8a
From: Erik Bernoth <ebernoth@redhat.com>
bffc8a
Date: Tue, 10 Nov 2020 18:32:40 +0100
bffc8a
Subject: [PATCH] [component] Add log verbosity from presets
bffc8a
bffc8a
Closes: #2289
bffc8a
bffc8a
The main problem this tries to solve was that preset verbosity was
bffc8a
ignored in logging.
bffc8a
bffc8a
With a simple test this could be reproduced:
bffc8a
sudo sh -c "source /path/to/repo/sosreport/venv/bin/activate; \
bffc8a
            cd /tmp/foo; sos report --preset sostestpreset; cd -"
bffc8a
bffc8a
The bug is that without a change of code there are no messages from the
bffc8a
plugin `host` (no lines of output start wiht "[plugin:host]").
bffc8a
bffc8a
The problem is that the logging is set in the inherited __init__() method
bffc8a
from Component, but the presets are only handled afterwards in the
bffc8a
Report's __init__().
bffc8a
bffc8a
Since it is good to have logging configured from the beginning, the
bffc8a
only option is to reconfigure it after the preset config is known.
bffc8a
bffc8a
The simplest method is to reinitialize the logging, although maybe not
bffc8a
the most efficient.
bffc8a
bffc8a
Signed-off-by: Erik Bernoth <ebernoth@redhat.com>
bffc8a
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
bffc8a
---
bffc8a
 sos/report/__init__.py | 6 ++++++
bffc8a
 1 file changed, 6 insertions(+)
bffc8a
bffc8a
diff --git a/sos/report/__init__.py b/sos/report/__init__.py
bffc8a
index 2e97010b..c6b0c21c 100644
bffc8a
--- a/sos/report/__init__.py
bffc8a
+++ b/sos/report/__init__.py
bffc8a
@@ -153,6 +153,12 @@ class SoSReport(SoSComponent):
bffc8a
         self.opts.merge(self.preset.opts)
bffc8a
         # re-apply any cmdline overrides to the preset
bffc8a
         self.opts = self.apply_options_from_cmdline(self.opts)
bffc8a
+        if hasattr(self.preset.opts, 'verbosity') and \
bffc8a
+            self.preset.opts.verbosity > 0:
bffc8a
+            print('\nWARNING: It is not recommended to set verbosity via the '
bffc8a
+                  'preset as it might have\nunforseen consequences for your '
bffc8a
+                  'report logs.\n')
bffc8a
+            self._setup_logging()
bffc8a
 
bffc8a
         self._set_directories()
bffc8a
 
bffc8a
-- 
bffc8a
2.26.2
bffc8a