fix: detect log rotation and reopen file handle for daily archiving
This commit is contained in:
parent
0139dff41c
commit
b1ef9e4b1f
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
import threading
|
import threading
|
||||||
@ -63,6 +64,15 @@ class MyLogger:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
break
|
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:
|
if fh is None:
|
||||||
fh = self._get_logger()
|
fh = self._get_logger()
|
||||||
fh.write(item)
|
fh.write(item)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user