Skip to content

Commit

Permalink
update-error-filename
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjiaqi authored and yinjiaqi committed Jan 1, 2025
1 parent 4741de2 commit 497e282
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions python/utils/logger_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 497e282

Please sign in to comment.