fix: detect log rotation and reopen file handle for daily archiving

This commit is contained in:
yumoqing 2026-05-31 09:33:39 +08:00
parent 0139dff41c
commit b1ef9e4b1f

View File

@ -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)