🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# 不再需要logging.handlers,已切换到基于时间戳的处理器
|
# 不再需要logging.handlers,已切换到基于时间戳的处理器
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
@@ -117,11 +118,11 @@ class TimestampedFileHandler(logging.Handler):
|
|||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
return
|
return
|
||||||
|
|
||||||
compressed_path = file_path.with_suffix(file_path.suffix + '.gz')
|
compressed_path = file_path.with_suffix(file_path.suffix + ".gz")
|
||||||
original_size = file_path.stat().st_size
|
original_size = file_path.stat().st_size
|
||||||
|
|
||||||
with open(file_path, 'rb') as f_in:
|
with open(file_path, "rb") as f_in:
|
||||||
with gzip.open(compressed_path, 'wb', compresslevel=self.compress_level) as f_out:
|
with gzip.open(compressed_path, "wb", compresslevel=self.compress_level) as f_out:
|
||||||
shutil.copyfileobj(f_in, f_out)
|
shutil.copyfileobj(f_in, f_out)
|
||||||
|
|
||||||
# 删除原文件
|
# 删除原文件
|
||||||
@@ -167,7 +168,7 @@ class TimestampedFileHandler(logging.Handler):
|
|||||||
# 写入日志
|
# 写入日志
|
||||||
if self.current_stream:
|
if self.current_stream:
|
||||||
msg = self.format(record)
|
msg = self.format(record)
|
||||||
self.current_stream.write(msg + '\n')
|
self.current_stream.write(msg + "\n")
|
||||||
self.current_stream.flush()
|
self.current_stream.flush()
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user