From 497e282362874727634beed396d16ed93b0567dc Mon Sep 17 00:00:00 2001 From: yinjiaqi Date: Wed, 1 Jan 2025 20:51:10 +0800 Subject: [PATCH] update-error-filename --- python/utils/logger_util.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/utils/logger_util.py b/python/utils/logger_util.py index e3766c22..29a723ff 100644 --- a/python/utils/logger_util.py +++ b/python/utils/logger_util.py @@ -100,7 +100,7 @@ def __init__(self, logger, extra, loglevel): LOGGING_CONFIG["loggers"]["appbuilder"]["handlers"] = [] log_file = os.environ.get("APPBUILDER_LOGFILE", "") if log_file: - ERROR_FILE_HEADER["filename"] = f"error.{log_file}" + ERROR_FILE_HEADER["filename"] = _add_error_to_file_name(log_file) FILE_HEADER["filename"] = log_file FILE_HEADER["level"] = loglevel LOGGING_CONFIG["handlers"]["file"] = FILE_HEADER @@ -153,11 +153,11 @@ def setFilename(self, filename): LOGGING_CONFIG["handlers"]["file"] = FILE_HEADER LOGGING_CONFIG["loggers"]["appbuilder"]["handlers"].append("file") if "error_file" not in LOGGING_CONFIG["loggers"]["appbuilder"]["handlers"]: - ERROR_FILE_HEADER["filename"] = f"error.{filename}" + ERROR_FILE_HEADER["filename"] = _add_error_to_file_name(filename) LOGGING_CONFIG["handlers"]["error_file"] = ERROR_FILE_HEADER LOGGING_CONFIG["loggers"]["appbuilder"]["handlers"].append("error_file") FILE_HEADER["filename"] = filename - ERROR_FILE_HEADER["filename"] = f"error.{filename}" + ERROR_FILE_HEADER["filename"] = _add_error_to_file_name(filename) LOGGING_CONFIG["handlers"]["file"] = FILE_HEADER LOGGING_CONFIG["handlers"]["error_file"] = ERROR_FILE_HEADER logging.config.dictConfig(LOGGING_CONFIG) @@ -218,7 +218,7 @@ def setLogConfig(self, # 设置文件名称 SET_CONFIG_HEADER['filename'] = file_name - ERROR_SET_CONFIG_HEADER['filename'] = f"error.{file_name}" + ERROR_SET_CONFIG_HEADER['filename'] = _add_error_to_file_name(file_name) # 设置滚动时间 SET_CONFIG_HEADER['when'] = when @@ -309,5 +309,11 @@ def get_logger(name, level=logging.INFO): logger.propagate = False return logger +def _add_error_to_file_name(filename): + prefix = "error." + dir_name, base_name = os.path.split(filename) + new_base_name = f"{prefix}{base_name}" + return os.path.join(dir_name, new_base_name) + logger = _setup_logging()