Update 2026-01-20 20:47:44
This commit is contained in:
Binary file not shown.
@@ -26,6 +26,35 @@ def setup_logging(app: Optional[object] = None) -> logging.Logger:
|
||||
log_dir = _ensure_log_dir()
|
||||
log_path = log_dir / "app.log"
|
||||
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
# [Fix] 앱 시작 시점에 app.log가 있고 날짜가 지났다면 강제 로테이션 (백업)
|
||||
# TimedRotatingFileHandler는 프로세스가 재시작되면 파일의 생성일을 기준으로
|
||||
# 롤오버를 즉시 수행하지 않고 append 모드로 여는 경우가 많음.
|
||||
# 이를 보완하기 위해, 직접 날짜를 확인하고 파일을 옮겨준다.
|
||||
# ─────────────────────────────────────────────────────────────
|
||||
if log_path.exists():
|
||||
try:
|
||||
from datetime import date
|
||||
|
||||
# 파일 마지막 수정 시간 확인
|
||||
mtime = os.path.getmtime(log_path)
|
||||
file_date = date.fromtimestamp(mtime)
|
||||
today = date.today()
|
||||
|
||||
# "파일 날짜" < "오늘" 이면 백업
|
||||
if file_date < today:
|
||||
backup_name = file_date.strftime("%Y-%m-%d.log")
|
||||
backup_path = log_dir / backup_name
|
||||
|
||||
# 이미 백업 파일이 있으면 굳이 덮어쓰거나 하지 않음(안전성)
|
||||
if not backup_path.exists():
|
||||
os.rename(log_path, backup_path)
|
||||
print(f"[Logger] Rotated old log file: app.log -> {backup_name}")
|
||||
|
||||
except Exception as e:
|
||||
# 권한 문제, 파일 잠금(Windows) 등으로 실패 시 무시하고 진행
|
||||
print(f"[Logger] Failed to force rotate log file: {e}")
|
||||
|
||||
root = logging.getLogger()
|
||||
root.setLevel(_DEF_LEVEL)
|
||||
root.propagate = False
|
||||
@@ -74,5 +103,5 @@ def setup_logging(app: Optional[object] = None) -> logging.Logger:
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
logging.getLogger("telegram").setLevel(logging.WARNING)
|
||||
|
||||
root.info("Logger initialized | level=%s | file=%s", _DEF_LEVEL, log_path)
|
||||
root.debug("Logger initialized | level=%s | file=%s", _DEF_LEVEL, log_path)
|
||||
return root
|
||||
Reference in New Issue
Block a user