Skip to content

Commit

Permalink
Added logfile rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
markqvist committed Oct 8, 2021
1 parent a2f18b1 commit 4ef369c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions RNS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
LOG_STDOUT = 0x91
LOG_FILE = 0x92

LOG_MAXSIZE = 5*1024*1024

loglevel = LOG_NOTICE
logfile = None
logdest = LOG_STDOUT
Expand Down Expand Up @@ -82,6 +84,13 @@ def log(msg, level=3, _override_destination = False):
file = open(logfile, "a")
file.write(logstring+"\n")
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()
except Exception as e:
logging_lock.release()
Expand Down

0 comments on commit 4ef369c

Please sign in to comment.