From 96b22672d64a32ebd8b6675f27cbf7309485af04 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 17 Apr 2024 15:56:43 +0200 Subject: [PATCH] remove common log level --- config.sample.yaml | 9 +++++---- matrix_alertbot/config.py | 9 +++++---- tests/resources/config/config.full.yml | 5 ++--- tests/test_config.py | 10 +++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/config.sample.yaml b/config.sample.yaml index 81c6c5e..cd01557 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -73,18 +73,19 @@ template: # Logging setup logging: - # Logging level - # Allowed levels are 'INFO', 'WARNING', 'ERROR', 'DEBUG' where DEBUG is most verbose - level: INFO + # Configure logging to a file file_logging: # Whether logging to a file is enabled enabled: false # Logging level specific to file logging (optional) - level: WARN + level: DEBUG # The path to the file to log to. May be relative or absolute filepath: matrix-alertbot.log # Configure logging to the console output console_logging: # Whether logging to the console is enabled enabled: true + # Logging level specific to console (optional) + # Allowed levels are 'INFO', 'WARNING', 'ERROR', 'DEBUG' where DEBUG is most verbose + level: INFO diff --git a/matrix_alertbot/config.py b/matrix_alertbot/config.py index 3bfe269..450304c 100644 --- a/matrix_alertbot/config.py +++ b/matrix_alertbot/config.py @@ -67,8 +67,9 @@ class Config: "%(asctime)s | %(name)s [%(levelname)s] %(message)s" ) - log_level = self._get_cfg(["logging", "level"], default="INFO") - logger.setLevel(log_level) + # this must be DEBUG to allow debug messages + # actual log levels are defined in the handlers below + logger.setLevel("DEBUG") file_logging_enabled = self._get_cfg( ["logging", "file_logging", "enabled"], default=False @@ -77,7 +78,7 @@ class Config: ["logging", "file_logging", "filepath"], default="matrix-alertbot.log" ) file_logging_log_level = self._get_cfg( - ["logging", "file_logging", "level"], required=False + ["logging", "file_logging", "level"], default="INFO" ) if file_logging_enabled: file_handler = logging.FileHandler(file_logging_filepath) @@ -90,7 +91,7 @@ class Config: ["logging", "console_logging", "enabled"], default=True ) console_logging_log_level = self._get_cfg( - ["logging", "console_logging", "level"], required=False + ["logging", "console_logging", "level"], default="INFO" ) if console_logging_enabled: console_handler = logging.StreamHandler(sys.stdout) diff --git a/tests/resources/config/config.full.yml b/tests/resources/config/config.full.yml index 15e8623..bb163d0 100644 --- a/tests/resources/config/config.full.yml +++ b/tests/resources/config/config.full.yml @@ -90,15 +90,14 @@ template: # Logging setup logging: - # Logging level - # Allowed levels are 'INFO', 'WARNING', 'ERROR', 'DEBUG' where DEBUG is most verbose - level: DEBUG # Configure logging to a file file_logging: # Whether logging to a file is enabled enabled: true # The path to the file to log to. May be relative or absolute filepath: fake.log + # Logging level specific to file (optional) + # Allowed levels are 'INFO', 'WARNING', 'ERROR', 'DEBUG' where DEBUG is most verbose level: INFO # Configure logging to the console output console_logging: diff --git a/tests/test_config.py b/tests/test_config.py index e30ab63..f7ed670 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -60,9 +60,9 @@ class ConfigTestCase(unittest.TestCase): fake_path_exists.assert_called_once_with("data/store") fake_mkdir.assert_called_once_with("data/store") - fake_logger.setLevel.assert_called_once_with("INFO") + fake_logger.setLevel.assert_called_once_with("DEBUG") fake_logger.addHandler.assert_called_once() - fake_logging.StreamHandler.return_value.setLevel("INFO") + fake_logging.StreamHandler.return_value.setLevel.assert_called_once_with("INFO") fake_logging.StreamHandler.assert_called_once_with(sys.stdout) self.assertEqual({"@fakes_user:matrix.example.com"}, config.user_ids) @@ -118,7 +118,7 @@ class ConfigTestCase(unittest.TestCase): fake_logger.setLevel.assert_called_once_with("DEBUG") fake_logger.addHandler.assert_called_once() - fake_logging.FileHandler.return_value.setLevel("DEBUG") + fake_logging.FileHandler.return_value.setLevel.assert_called_once_with("INFO") fake_logging.FileHandler.assert_called_once_with("fake.log") self.assertEqual( @@ -410,8 +410,8 @@ class ConfigTestCase(unittest.TestCase): self.assertEqual(2, fake_logger.addHandler.call_count) fake_logger.setLevel.assert_called_once_with("DEBUG") - fake_logging.FileHandler.return_value.setLevel.assert_called_with("WARN") - fake_logging.StreamHandler.return_value.setLevel.assert_called_with("ERROR") + fake_logging.FileHandler.return_value.setLevel.assert_called_once_with("WARN") + fake_logging.StreamHandler.return_value.setLevel.assert_called_once_with("ERROR") if __name__ == "__main__":