diff --git a/RNS/__init__.py b/RNS/__init__.py index 9a8b5a7..493bd60 100755 --- a/RNS/__init__.py +++ b/RNS/__init__.py @@ -149,14 +149,10 @@ def log(msg, level=3, _override_destination = False, pt=False): elif (logdest == LOG_FILE and logfile != None): try: - file = open(logfile, "a") - file.write(logstring+"\n") - file.close() - + 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) + if os.path.isfile(prevfile): os.unlink(prevfile) os.rename(logfile, prevfile) except Exception as e: @@ -166,8 +162,7 @@ def log(msg, level=3, _override_destination = False, pt=False): log(msg, level) elif logdest == LOG_CALLBACK: - try: - logcall(logstring) + try: logcall(logstring) except Exception as e: _always_override_destination = True log("Exception occurred while calling external log handler: "+str(e), LOG_CRITICAL)