From 55d71cecdd6be29ee53ba421fa52b26cdc698ff1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 8 Mar 2025 13:19:42 +0100 Subject: [PATCH] refactor: move root-handler adding to separate function --- freqtrade/loggers/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/freqtrade/loggers/__init__.py b/freqtrade/loggers/__init__.py index c6294370d..eb814c2d9 100644 --- a/freqtrade/loggers/__init__.py +++ b/freqtrade/loggers/__init__.py @@ -96,11 +96,16 @@ FT_LOGGING_CONFIG = { } +def _add_root_handler(log_config: dict[str, Any], handler_name: str): + if handler_name not in log_config["root"]["handlers"]: + log_config["root"]["handlers"].append(handler_name) + + def _create_log_config(config: Config) -> dict[str, Any]: # Get log_config from user config or use default log_config = config.get("log_config", FT_LOGGING_CONFIG.copy()) - # Dynamically update any FtRichHandler with the error_console + # Dynamically update any FtRichHandler with the proper console object for handler_config in log_config.get("handlers", {}).values(): if handler_config.get("class") == "freqtrade.loggers.ft_rich_handler.FtRichHandler": handler_config["console"] = error_console @@ -119,9 +124,7 @@ def _create_log_config(config: Config) -> dict[str, Any]: log_config["formatters"]["syslog_format"] = { "format": "%(name)s - %(levelname)s - %(message)s" } - # Add handler to root - if "syslog" not in log_config["root"]["handlers"]: - log_config["root"]["handlers"].append("syslog") + _add_root_handler(log_config, "syslog") elif s[0] == "journald": # pragma: no cover # Check if we have the module available @@ -143,9 +146,7 @@ def _create_log_config(config: Config) -> dict[str, Any]: log_config["formatters"]["journald_format"] = { "format": "%(name)s - %(levelname)s - %(message)s" } - # Add handler to root - if "journald" not in log_config["root"]["handlers"]: - log_config["root"]["handlers"].append("journald") + _add_root_handler(log_config, "journald") else: # Regular file logging