From fde9114b27abb8b878416140eb8d104d70ac0898 Mon Sep 17 00:00:00 2001 From: cheng zhen Date: Fri, 10 Jan 2025 22:29:21 +0800 Subject: [PATCH] feat: enhance logger functionality with initialization info and code formatting improvements --- logger.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/logger.py b/logger.py index 0aa7e5e..88d2e50 100644 --- a/logger.py +++ b/logger.py @@ -11,9 +11,10 @@ logging.basicConfig( filename=os.path.join(log_dir, f"{datetime.now().strftime('%Y-%m-%d')}.log"), level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s", - encoding='utf-8', + encoding="utf-8", ) + # 创建控制台处理器 console_handler = logging.StreamHandler() console_handler.setLevel(logging.INFO) @@ -22,6 +23,10 @@ console_handler.setFormatter(logging.Formatter("%(message)s")) # 将控制台处理器添加到日志记录器 logging.getLogger().addHandler(console_handler) +# 打印日志目录所在路径 +logging.info(f"Logger initialized, log directory: {os.path.abspath(log_dir)}") + + def main_task(): """ Main task execution function. Simulates a workflow and handles errors. @@ -42,6 +47,7 @@ def main_task(): finally: logging.info("Task execution finished.") + def some_condition(): """ Simulates an error condition. Returns True to trigger an error. @@ -49,6 +55,7 @@ def some_condition(): """ return True + if __name__ == "__main__": # Application workflow logging.info("Application started.")