mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-10-26 10:51:49 -04:00
Full and configurable logfile rotation.
This commit is contained in:
parent
956d688e10
commit
1694a17a75
1 changed files with 13 additions and 4 deletions
|
|
@ -77,7 +77,8 @@ LOG_STDOUT = 0x91
|
|||
LOG_FILE = 0x92
|
||||
LOG_CALLBACK = 0x93
|
||||
|
||||
LOG_MAXSIZE = 5*1024*1024
|
||||
LOG_MAXSIZE = 30*1024*1024
|
||||
LOG_MAXROT = 9
|
||||
|
||||
loglevel = LOG_NOTICE
|
||||
logfile = None
|
||||
|
|
@ -144,9 +145,17 @@ def log(msg, level=3, _override_destination = False, pt=False):
|
|||
try:
|
||||
with open(logfile, "a") as file: file.write(logstring+"\n")
|
||||
if os.path.getsize(logfile) > LOG_MAXSIZE:
|
||||
prevfile = logfile+".1"
|
||||
if os.path.isfile(prevfile): os.unlink(prevfile)
|
||||
os.rename(logfile, prevfile)
|
||||
for i in range(LOG_MAXROT, 0, -1):
|
||||
oldfile = f"{logfile}.{i}"
|
||||
if os.path.isfile(oldfile):
|
||||
if i == LOG_MAXROT:
|
||||
os.unlink(oldfile)
|
||||
else:
|
||||
rotfile = f"{logfile}.{i+1}"
|
||||
os.rename(oldfile, rotfile)
|
||||
|
||||
rotfile = f"{logfile}.1"
|
||||
os.rename(logfile, rotfile)
|
||||
|
||||
except Exception as e:
|
||||
_always_override_destination = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue