From b2f09957e818a7adaabcd988110af3d3c6e127af Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Jun 2025 14:02:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/logger.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 89d0f1738..415b9b678 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -69,7 +69,9 @@ def get_console_handler(): class TimestampedFileHandler(logging.Handler): """基于时间戳的文件处理器,避免重命名操作""" - def __init__(self, log_dir, max_bytes=10*1024*1024, backup_count=5, encoding='utf-8', compress=True, compress_level=6): + def __init__( + self, log_dir, max_bytes=10 * 1024 * 1024, backup_count=5, encoding="utf-8", compress=True, compress_level=6 + ): super().__init__() self.log_dir = Path(log_dir) self.log_dir.mkdir(exist_ok=True) @@ -79,7 +81,7 @@ class TimestampedFileHandler(logging.Handler): self.compress = compress self.compress_level = compress_level self._lock = threading.Lock() - + # 当前活跃的日志文件 self.current_file = None self.current_stream = None @@ -89,7 +91,7 @@ class TimestampedFileHandler(logging.Handler): """初始化当前日志文件""" timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") self.current_file = self.log_dir / f"app_{timestamp}.log.jsonl" - self.current_stream = open(self.current_file, 'a', encoding=self.encoding) + self.current_stream = open(self.current_file, "a", encoding=self.encoding) def _should_rollover(self): """检查是否需要轮转""" @@ -101,14 +103,14 @@ class TimestampedFileHandler(logging.Handler): """执行轮转:关闭当前文件,创建新文件""" if self.current_stream: self.current_stream.close() - + # 压缩旧文件 if self.compress and self.current_file: threading.Thread(target=self._compress_file, args=(self.current_file,), daemon=True).start() - + # 清理旧文件 self._cleanup_old_files() - + # 创建新文件 self._init_current_file()