diff --git a/src/corelibs/config_handling/settings_loader.py b/src/corelibs/config_handling/settings_loader.py index b4bd8ee..c407a0b 100644 --- a/src/corelibs/config_handling/settings_loader.py +++ b/src/corelibs/config_handling/settings_loader.py @@ -577,7 +577,7 @@ class SettingsLoader: self.log.logger.log(Log.get_log_level_int(level), msg, stacklevel=2) if self.log is None or self.always_print: if print_error: - print(msg) + print(f"[SettingsLoader] {msg}") if level == 'ERROR': # remove any prefix [!] for error message list self.__error_msg.append(msg.replace('[!] ', '').strip()) diff --git a/src/corelibs/logging_handling/log.py b/src/corelibs/logging_handling/log.py index 319bd31..f0a5542 100644 --- a/src/corelibs/logging_handling/log.py +++ b/src/corelibs/logging_handling/log.py @@ -602,9 +602,9 @@ class Log(LogParent): __setting = self.DEFAULT_LOG_SETTINGS.get(__log_entry, True) default_log_settings[__log_entry] = __setting # check console log type - default_log_settings['console_format_type'] = cast('ConsoleFormat', log_settings.get( - 'console_format_type', self.DEFAULT_LOG_SETTINGS['console_format_type'] - )) + if (console_format_type := log_settings.get('console_format_type')) is None: + console_format_type = self.DEFAULT_LOG_SETTINGS['console_format_type'] + default_log_settings['console_format_type'] = cast('ConsoleFormat', console_format_type) # check log queue __setting = log_settings.get('log_queue', self.DEFAULT_LOG_SETTINGS['log_queue']) if __setting is not None: diff --git a/test-run/logging_handling/log.py b/test-run/logging_handling/log.py index 5f6b0f0..6379538 100644 --- a/test-run/logging_handling/log.py +++ b/test-run/logging_handling/log.py @@ -27,7 +27,8 @@ def main(): "per_run_log": True, # "console_format_type": ConsoleFormatSettings.NONE, # "console_format_type": ConsoleFormatSettings.MINIMAL, - "console_format_type": ConsoleFormat.TIME_MICROSECONDS | ConsoleFormat.NAME | ConsoleFormat.LEVEL, + # "console_format_type": ConsoleFormat.TIME_MICROSECONDS | ConsoleFormat.NAME | ConsoleFormat.LEVEL, + "console_format_type": None, # "console_format_type": ConsoleFormat.NAME, # "console_format_type": ( # ConsoleFormat.TIME | ConsoleFormat.TIMEZONE | ConsoleFormat.LINENO | ConsoleFormat.LEVEL diff --git a/tests/unit/logging_handling/log_testing/test_log_3_custom_console_formatter.py b/tests/unit/logging_handling/log_testing/test_log_3_custom_console_formatter.py index cd68375..5f5a753 100644 --- a/tests/unit/logging_handling/log_testing/test_log_3_custom_console_formatter.py +++ b/tests/unit/logging_handling/log_testing/test_log_3_custom_console_formatter.py @@ -28,6 +28,7 @@ def tmp_log_path(tmp_path: Path) -> Path: @pytest.fixture def basic_log_settings() -> LogSettings: """Basic log settings for testing""" + # Return a new dict each time to avoid state pollution return { "log_level_console": LoggingLevel.WARNING, "log_level_file": LoggingLevel.DEBUG, @@ -308,4 +309,54 @@ class TestUpdateConsoleFormatter: # Verify message was logged assert "Test warning message" in caplog.text + def test_log_console_format_option_set_to_none( + self, tmp_log_path: Path + ): + """Test that when log_console_format option is set to None, it uses ConsoleFormatSettings.ALL""" + # Save the original DEFAULT_LOG_SETTINGS to restore it after test + original_default = Log.DEFAULT_LOG_SETTINGS.copy() + + try: + # Reset DEFAULT_LOG_SETTINGS to ensure clean state + Log.DEFAULT_LOG_SETTINGS = { + "log_level_console": Log.DEFAULT_LOG_LEVEL_CONSOLE, + "log_level_file": Log.DEFAULT_LOG_LEVEL_FILE, + "per_run_log": False, + "console_enabled": True, + "console_color_output_enabled": True, + "console_format_type": ConsoleFormatSettings.ALL, + "add_start_info": True, + "add_end_info": False, + "log_queue": None, + } + + # Create a fresh settings dict with console_format_type explicitly set to None + settings: LogSettings = { + "log_level_console": LoggingLevel.WARNING, + "log_level_file": LoggingLevel.DEBUG, + "per_run_log": False, + "console_enabled": True, + "console_color_output_enabled": False, + "console_format_type": None, # type: ignore + "add_start_info": False, + "add_end_info": False, + "log_queue": None, + } + + # Verify that None is explicitly set in the input + assert settings['console_format_type'] is None + + log = Log( + log_path=tmp_log_path, + log_name="test_log", + log_settings=settings + ) + + # Verify that None was replaced with ConsoleFormatSettings.ALL + # The Log class should replace None with the default value (ALL) + assert log.log_settings['console_format_type'] == ConsoleFormatSettings.ALL + finally: + # Restore original DEFAULT_LOG_SETTINGS + Log.DEFAULT_LOG_SETTINGS = original_default + # __END__