Skip to content

Commit

Permalink
allow backcompat mode for logging (#18810)
Browse files Browse the repository at this point in the history
* allow backcompat mode for logging

* fix stdout
  • Loading branch information
wjblanke authored Nov 4, 2024
1 parent bef7a5d commit d95a5e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions chia/util/chia_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,31 @@ 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] = []
if logging_config["log_stdout"]:
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,
)
Expand Down
1 change: 1 addition & 0 deletions chia/util/initial-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d95a5e7

Please sign in to comment.