Silence Flask access logs and retain PM2 logs for 3 days.

Stop werkzeug request spam into PM2 error files, truncate oversized logs, and install daily logrotate with 3-day retention.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 07:53:19 +08:00
parent 8ecc70a61c
commit 1e765f4b2b
7 changed files with 108 additions and 1 deletions
+16
View File
@@ -0,0 +1,16 @@
"""关闭 Flask/Werkzeug 开发服务器 access log 刷屏(避免灌满 PM2 error 日志)."""
from __future__ import annotations
import logging
def silence_werkzeug_access_log() -> None:
"""仅抑制 request access 行;WARNING/ERROR 仍可读."""
log = logging.getLogger("werkzeug")
log.setLevel(logging.WARNING)
# 部分环境会挂 StreamHandler 到 stderr;抬高阈值即可
for h in list(log.handlers):
try:
h.setLevel(logging.WARNING)
except Exception:
pass