Skip to content

Commit 4ef369c

Browse files
committed
Added logfile rotation
1 parent a2f18b1 commit 4ef369c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

RNS/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
LOG_STDOUT = 0x91
3232
LOG_FILE = 0x92
3333

34+
LOG_MAXSIZE = 5*1024*1024
35+
3436
loglevel = LOG_NOTICE
3537
logfile = None
3638
logdest = LOG_STDOUT
@@ -82,6 +84,13 @@ def log(msg, level=3, _override_destination = False):
8284
file = open(logfile, "a")
8385
file.write(logstring+"\n")
8486
file.close()
87+
88+
if os.path.getsize(logfile) > LOG_MAXSIZE:
89+
prevfile = logfile+".1"
90+
if os.path.isfile(prevfile):
91+
os.unlink(prevfile)
92+
os.rename(logfile, prevfile)
93+
8594
logging_lock.release()
8695
except Exception as e:
8796
logging_lock.release()

0 commit comments

Comments
 (0)