refactor: move root-handler adding to separate function
This commit is contained in:
@@ -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]:
|
def _create_log_config(config: Config) -> dict[str, Any]:
|
||||||
# Get log_config from user config or use default
|
# Get log_config from user config or use default
|
||||||
log_config = config.get("log_config", FT_LOGGING_CONFIG.copy())
|
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():
|
for handler_config in log_config.get("handlers", {}).values():
|
||||||
if handler_config.get("class") == "freqtrade.loggers.ft_rich_handler.FtRichHandler":
|
if handler_config.get("class") == "freqtrade.loggers.ft_rich_handler.FtRichHandler":
|
||||||
handler_config["console"] = error_console
|
handler_config["console"] = error_console
|
||||||
@@ -119,9 +124,7 @@ def _create_log_config(config: Config) -> dict[str, Any]:
|
|||||||
log_config["formatters"]["syslog_format"] = {
|
log_config["formatters"]["syslog_format"] = {
|
||||||
"format": "%(name)s - %(levelname)s - %(message)s"
|
"format": "%(name)s - %(levelname)s - %(message)s"
|
||||||
}
|
}
|
||||||
# Add handler to root
|
_add_root_handler(log_config, "syslog")
|
||||||
if "syslog" not in log_config["root"]["handlers"]:
|
|
||||||
log_config["root"]["handlers"].append("syslog")
|
|
||||||
|
|
||||||
elif s[0] == "journald": # pragma: no cover
|
elif s[0] == "journald": # pragma: no cover
|
||||||
# Check if we have the module available
|
# 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"] = {
|
log_config["formatters"]["journald_format"] = {
|
||||||
"format": "%(name)s - %(levelname)s - %(message)s"
|
"format": "%(name)s - %(levelname)s - %(message)s"
|
||||||
}
|
}
|
||||||
# Add handler to root
|
_add_root_handler(log_config, "journald")
|
||||||
if "journald" not in log_config["root"]["handlers"]:
|
|
||||||
log_config["root"]["handlers"].append("journald")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Regular file logging
|
# Regular file logging
|
||||||
|
|||||||
Reference in New Issue
Block a user