执行 Ruff 安全自动修复
This commit is contained in:
+3
-4
@@ -14,7 +14,6 @@ from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
_LOG_LEVELS = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
|
||||
_DEFAULT_RETENTION_DAYS = 14
|
||||
_DEFAULT_ROTATION_SIZE = 50 * 1024 * 1024
|
||||
@@ -36,7 +35,7 @@ def _parse_positive_int(value: str | None, default: int) -> int:
|
||||
|
||||
def _parse_size(value: str | None, default: int = _DEFAULT_ROTATION_SIZE) -> int:
|
||||
"""解析 50M、1GiB 等易读大小;非法值保持安全默认值。"""
|
||||
matched = re.fullmatch(r"\s*(\d+)\s*([kmgt]?i?b?)?\s*", str(value or ""), re.I)
|
||||
matched = re.fullmatch(r"\s*(\d+)\s*([kmgt]?i?b?)?\s*", str(value or ""), re.IGNORECASE)
|
||||
if not matched:
|
||||
return default
|
||||
amount = int(matched.group(1))
|
||||
@@ -113,7 +112,7 @@ class _SizeAndDayRotatingFileHandler(BaseRotatingHandler):
|
||||
self._log_dir / f"{self._filename_prefix}-{day.isoformat()}{self._suffix}"
|
||||
)
|
||||
|
||||
def shouldRollover(self, record: logging.LogRecord) -> bool: # noqa: N802
|
||||
def shouldRollover(self, record: logging.LogRecord) -> bool:
|
||||
if datetime.now().date() != self._active_day:
|
||||
return True
|
||||
if self.stream is None:
|
||||
@@ -122,7 +121,7 @@ class _SizeAndDayRotatingFileHandler(BaseRotatingHandler):
|
||||
message = f"{self.format(record)}\n"
|
||||
return self.stream.tell() + len(message.encode("utf-8")) >= self.max_bytes
|
||||
|
||||
def doRollover(self) -> None: # noqa: N802
|
||||
def doRollover(self) -> None:
|
||||
if self.stream is not None:
|
||||
self.stream.close()
|
||||
self.stream = None
|
||||
|
||||
Reference in New Issue
Block a user