Blob Blame History Raw
From 169898b47b26734a8cdcb748157f7314f7f8821b Mon Sep 17 00:00:00 2001
From: Erik Bernoth <ebernoth@redhat.com>
Date: Tue, 10 Nov 2020 18:32:40 +0100
Subject: [PATCH] [component] Add log verbosity from presets

Closes: #2289

The main problem this tries to solve was that preset verbosity was
ignored in logging.

With a simple test this could be reproduced:
sudo sh -c "source /path/to/repo/sosreport/venv/bin/activate; \
            cd /tmp/foo; sos report --preset sostestpreset; cd -"

The bug is that without a change of code there are no messages from the
plugin `host` (no lines of output start wiht "[plugin:host]").

The problem is that the logging is set in the inherited __init__() method
from Component, but the presets are only handled afterwards in the
Report's __init__().

Since it is good to have logging configured from the beginning, the
only option is to reconfigure it after the preset config is known.

The simplest method is to reinitialize the logging, although maybe not
the most efficient.

Signed-off-by: Erik Bernoth <ebernoth@redhat.com>
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
---
 sos/report/__init__.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sos/report/__init__.py b/sos/report/__init__.py
index 2e97010b..c6b0c21c 100644
--- a/sos/report/__init__.py
+++ b/sos/report/__init__.py
@@ -153,6 +153,12 @@ class SoSReport(SoSComponent):
         self.opts.merge(self.preset.opts)
         # re-apply any cmdline overrides to the preset
         self.opts = self.apply_options_from_cmdline(self.opts)
+        if hasattr(self.preset.opts, 'verbosity') and \
+            self.preset.opts.verbosity > 0:
+            print('\nWARNING: It is not recommended to set verbosity via the '
+                  'preset as it might have\nunforseen consequences for your '
+                  'report logs.\n')
+            self._setup_logging()
 
         self._set_directories()
 
-- 
2.26.2