From 4ef369cdd8af9fa4324962199df0181e92a11b81 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 8 Oct 2021 19:23:10 +0200 Subject: [PATCH] Added logfile rotation --- RNS/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/RNS/__init__.py b/RNS/__init__.py index e77b1ed..f08e340 100755 --- a/RNS/__init__.py +++ b/RNS/__init__.py @@ -31,6 +31,8 @@ LOG_EXTREME = 7 LOG_STDOUT = 0x91 LOG_FILE = 0x92 +LOG_MAXSIZE = 5*1024*1024 + loglevel = LOG_NOTICE logfile = None logdest = LOG_STDOUT @@ -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()