From ef161b517017d2cfeae08475cf366dc7243c468f Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 29 Apr 2024 23:16:07 +0100 Subject: [PATCH] Re-align logging levels for file vs. stdout For both we want to default to DEBUG and still allow unit tests to override. --- hotsos/core/config.py | 3 ++- hotsos/core/log.py | 14 ++++---------- tests/unit/utils.py | 5 ++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/hotsos/core/config.py b/hotsos/core/config.py index 236cc779a..9df4ba905 100644 --- a/hotsos/core/config.py +++ b/hotsos/core/config.py @@ -85,7 +85,8 @@ def __init__(self): description='Version of hotsos being run.', default_value=None, value_type=str)) self.add(ConfigOpt(name='debug_mode', - description='Set to True to enable debug logging', + description='Set to True to enable debug logging ' + 'to standard output', default_value=False, value_type=bool)) self.add(ConfigOpt(name='plugin_yaml_defs', description='Path to yaml-defined checks.', diff --git a/hotsos/core/log.py b/hotsos/core/log.py index 6a8ea7e53..95f5773e7 100644 --- a/hotsos/core/log.py +++ b/hotsos/core/log.py @@ -48,17 +48,11 @@ def setup_deps_loggers(self): logger.removeHandler(logger.handlers[0]) logger.addHandler(self._handler) - if HotSOSConfig.debug_mode: - level = HotSOSConfig.debug_log_levels.get(dep, 'WARNING') - logger.setLevel(level=level) - - def start(self, level=None): - if level is None and HotSOSConfig.debug_mode: - level = logging.DEBUG - - if level is not None: - log.setLevel(level) + level = HotSOSConfig.debug_log_levels.get(dep, 'WARNING') + logger.setLevel(level=level) + def start(self, level=logging.DEBUG): + log.setLevel(level) if log.hasHandlers(): return diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 6db4b948e..1d3efab74 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -424,9 +424,7 @@ def __init__(self, *args, **kwargs): 'plugin_tmp_dir': None, 'use_all_logs': True, 'machine_readable': True, - 'debug_mode': True, - 'debug_log_levels': {'propertree': 'WARNING', - 'searchkit': 'INFO'}} + 'debug_mode': True} def part_output_to_actual(self, output): actual = {} @@ -450,6 +448,7 @@ def setUp(self): if os.environ.get('TESTS_LOG_LEVEL_DEBUG', 'no') == 'yes': LoggingManager().start() else: + HotSOSConfig.debug_log_levels['searchkit'] = 'WARNING' LoggingManager().start(level=logging.WARNING) def _addDuration(self, *args, **kwargs): # For Python >= 3.12