diff --git a/.github/scripts/check_log.py b/.github/scripts/check_log.py index 77a4dd2..565fdf2 100644 --- a/.github/scripts/check_log.py +++ b/.github/scripts/check_log.py @@ -5,7 +5,7 @@ import urllib.request as request url = os.environ["LOG_URL"] path_answer = ".github/scripts/answers" -for index in range(0,3): +for _ in range(0,3): try: with request.urlopen(url,timeout=30.0) as r: log_bytes = r.read() @@ -62,4 +62,4 @@ else: if cfproxy_end is True: print(str(path_answer + "/default.md")) else: - print(str(path_answer + "/no_cfproxy.md")) \ No newline at end of file + print(str(path_answer + "/no_cfproxy.md")) diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml index 5069f57..acad200 100644 --- a/.github/workflows/issue-triage.yml +++ b/.github/workflows/issue-triage.yml @@ -34,7 +34,6 @@ jobs: python-version: "3.14" - name: Clone folder - if: steps.log.outputs.found == 'true' uses: actions/checkout@v4 with: sparse-checkout: | @@ -57,4 +56,4 @@ jobs: uses: peter-evans/create-or-update-comment@v5 with: issue-number: ${{ github.event.issue.number }} - body-path: ${{ steps.log.outputs.found == 'true' && steps.comment.outputs.com || '.github/scripts/answers/default.md' }} \ No newline at end of file + body-path: ${{ steps.log.outputs.found == 'true' && steps.comment.outputs.com || '.github/scripts/answers/default.md' }} diff --git a/proxy/tg_ws_proxy.py b/proxy/tg_ws_proxy.py index 92cd961..89e7fc0 100644 --- a/proxy/tg_ws_proxy.py +++ b/proxy/tg_ws_proxy.py @@ -695,7 +695,6 @@ def main(): log_max_mb=args.log_max_mb, backups=args.log_backups, ) - fh.setFormatter(log_fmt) fh.addFilter(DomainCensorFilter()) root.addHandler(fh) diff --git a/utils/logging_setup.py b/utils/logging_setup.py index b1dade9..38e2c18 100644 --- a/utils/logging_setup.py +++ b/utils/logging_setup.py @@ -1,4 +1,4 @@ -"""Shared construction of the rotating log file handler. +"""Shared construction and formatting of the rotating log file handler. Centralizes the rotation invariant so both the tray and the CLI log paths behave identically and the file can never grow without bound (issue #885). @@ -31,9 +31,14 @@ def build_log_handler( """ max_bytes = max(_MIN_BYTES, int(log_max_mb * 1024 * 1024)) backup_count = max(_MIN_BACKUPS, int(backups)) - return logging.handlers.RotatingFileHandler( + handler = logging.handlers.RotatingFileHandler( path, maxBytes=max_bytes, backupCount=backup_count, encoding="utf-8", ) + handler.setFormatter(logging.Formatter( + "%(asctime)s %(levelname)-5s %(name)s %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + )) + return handler diff --git a/utils/tray_common.py b/utils/tray_common.py index d5171e7..93386fd 100644 --- a/utils/tray_common.py +++ b/utils/tray_common.py @@ -225,7 +225,6 @@ def save_config(cfg: dict) -> None: # logging -_LOG_FMT_FILE = "%(asctime)s %(levelname)-5s %(name)s %(message)s" _LOG_FMT_CONSOLE = "%(asctime)s %(levelname)-5s %(message)s" @@ -238,7 +237,6 @@ def setup_logging(verbose: bool = False, log_max_mb: float = 5) -> None: fh = build_log_handler(str(LOG_FILE), log_max_mb=log_max_mb, backups=1) fh.setLevel(logging.DEBUG) - fh.setFormatter(logging.Formatter(_LOG_FMT_FILE, datefmt="%Y-%m-%d %H:%M:%S")) fh.addFilter(DomainCensorFilter()) root.addHandler(fh)