diff --git a/RNS/__init__.py b/RNS/__init__.py index e38684cd..4a3211b0 100755 --- a/RNS/__init__.py +++ b/RNS/__init__.py @@ -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