From b1ef9e4b1f561c616b351d34d57f9c5b83970773 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 31 May 2026 09:33:39 +0800 Subject: [PATCH] fix: detect log rotation and reopen file handle for daily archiving --- appPublic/log.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/appPublic/log.py b/appPublic/log.py index 139837b..410a9a2 100644 --- a/appPublic/log.py +++ b/appPublic/log.py @@ -1,3 +1,4 @@ +import os import sys import codecs import threading @@ -63,6 +64,15 @@ class MyLogger: except Exception: pass break + # Detect log rotation: if file was moved/renamed, reopen + if fh is not None and self.logfile and not os.path.exists(self.logfile): + try: + fh.flush() + fh.close() + except Exception: + pass + fh = None + self.logger = None if fh is None: fh = self._get_logger() fh.write(item)