🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -69,7 +69,9 @@ def get_console_handler():
|
|||||||
class TimestampedFileHandler(logging.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__()
|
super().__init__()
|
||||||
self.log_dir = Path(log_dir)
|
self.log_dir = Path(log_dir)
|
||||||
self.log_dir.mkdir(exist_ok=True)
|
self.log_dir.mkdir(exist_ok=True)
|
||||||
@@ -89,7 +91,7 @@ class TimestampedFileHandler(logging.Handler):
|
|||||||
"""初始化当前日志文件"""
|
"""初始化当前日志文件"""
|
||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
self.current_file = self.log_dir / f"app_{timestamp}.log.jsonl"
|
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):
|
def _should_rollover(self):
|
||||||
"""检查是否需要轮转"""
|
"""检查是否需要轮转"""
|
||||||
|
|||||||
Reference in New Issue
Block a user