mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 23:40:18 +00:00
Added logfile rotation
This commit is contained in:
parent
a2f18b1daf
commit
4ef369cdd8
@ -31,6 +31,8 @@ LOG_EXTREME = 7
|
|||||||
LOG_STDOUT = 0x91
|
LOG_STDOUT = 0x91
|
||||||
LOG_FILE = 0x92
|
LOG_FILE = 0x92
|
||||||
|
|
||||||
|
LOG_MAXSIZE = 5*1024*1024
|
||||||
|
|
||||||
loglevel = LOG_NOTICE
|
loglevel = LOG_NOTICE
|
||||||
logfile = None
|
logfile = None
|
||||||
logdest = LOG_STDOUT
|
logdest = LOG_STDOUT
|
||||||
@ -82,6 +84,13 @@ def log(msg, level=3, _override_destination = False):
|
|||||||
file = open(logfile, "a")
|
file = open(logfile, "a")
|
||||||
file.write(logstring+"\n")
|
file.write(logstring+"\n")
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
if os.path.getsize(logfile) > LOG_MAXSIZE:
|
||||||
|
prevfile = logfile+".1"
|
||||||
|
if os.path.isfile(prevfile):
|
||||||
|
os.unlink(prevfile)
|
||||||
|
os.rename(logfile, prevfile)
|
||||||
|
|
||||||
logging_lock.release()
|
logging_lock.release()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging_lock.release()
|
logging_lock.release()
|
||||||
|
Loading…
Reference in New Issue
Block a user