From d95a5e7cf6459e86650cfb73e08ec8957a069dfe Mon Sep 17 00:00:00 2001 From: wjblanke Date: Mon, 4 Nov 2024 11:33:40 -0800 Subject: [PATCH] allow backcompat mode for logging (#18810) * allow backcompat mode for logging * fix stdout --- chia/util/chia_logging.py | 18 ++++++++++++++---- chia/util/initial-config.yaml | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/chia/util/chia_logging.py b/chia/util/chia_logging.py index 3cd525fdf3d1..b36a758c0b9d 100644 --- a/chia/util/chia_logging.py +++ b/chia/util/chia_logging.py @@ -49,12 +49,17 @@ def initialize_logging( root_path: Path, beta_root_path: Optional[Path] = None, ) -> None: + log_backcompat = logging_config.get("log_backcompat", False) log_level = logging_config.get("log_level", default_log_level) file_name_length = 33 - len(service_name) log_date_format = "%Y-%m-%dT%H:%M:%S" file_log_formatter = logging.Formatter( - fmt=f"%(asctime)s.%(msecs)03d {__version__} {service_name} %(name)-{file_name_length}s: " - f"%(levelname)-8s %(message)s", + fmt=( + f"%(asctime)s.%(msecs)03d {service_name} %(name)-{file_name_length}s: %(levelname)-8s %(message)s" + if log_backcompat + else f"%(asctime)s.%(msecs)03d {__version__} {service_name} %(name)-{file_name_length}s: " + f"%(levelname)-8s %(message)s" + ), datefmt=log_date_format, ) handlers: list[logging.Handler] = [] @@ -62,8 +67,13 @@ def initialize_logging( stdout_handler = colorlog.StreamHandler() stdout_handler.setFormatter( colorlog.ColoredFormatter( - f"%(asctime)s.%(msecs)03d {__version__} {service_name} %(name)-{file_name_length}s: " - f"%(log_color)s%(levelname)-8s%(reset)s %(message)s", + ( + f"%(asctime)s.%(msecs)03d {service_name} %(name)-{file_name_length}s: " + f"%(log_color)s%(levelname)-8s%(reset)s %(message)s" + if log_backcompat + else f"%(asctime)s.%(msecs)03d {__version__} {service_name} %(name)-{file_name_length}s: " + f"%(log_color)s%(levelname)-8s%(reset)s %(message)s" + ), datefmt=log_date_format, reset=True, ) diff --git a/chia/util/initial-config.yaml b/chia/util/initial-config.yaml index f913ae4c9b54..74419854ffe4 100644 --- a/chia/util/initial-config.yaml +++ b/chia/util/initial-config.yaml @@ -86,6 +86,7 @@ daemon_ssl: # Controls logging of all servers (harvester, farmer, etc..). Each one can be overridden. logging: &logging log_stdout: False # If True, outputs to stdout instead of a file + log_backcompat: False log_filename: "log/debug.log" log_level: "WARNING" # Can be CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET log_maxfilesrotation: 7 # Max files in rotation. Default value 7 if the key is not set