checkSize() function optimized
This commit is contained in:
parent
6f8d7c2759
commit
4ac4cb8e91
@ -30,8 +30,7 @@ def checkSize(logs_folder=f"logs{sep}", log_size=1024) -> None:
|
||||
* logs_folder (str, optional): Folder where logs stored. Defaults to "logs/".
|
||||
* log_size (int, optional): How many bytes should file containt to be rotated. Defaults to 1024.
|
||||
"""
|
||||
i = 0
|
||||
while i < 2:
|
||||
makedirs(logs_folder, exist_ok=True)
|
||||
try:
|
||||
log = stat(logs_folder + 'latest.log')
|
||||
if (log.st_size / 1024) > log_size:
|
||||
@ -39,19 +38,9 @@ def checkSize(logs_folder=f"logs{sep}", log_size=1024) -> None:
|
||||
with gzipopen(f'{logs_folder}{datetime.now().strftime("%d.%m.%Y_%H:%M:%S")}.zip', 'wb') as f_out:
|
||||
copyfileobj(f_in, f_out)
|
||||
open(logs_folder + 'latest.log', 'w').close()
|
||||
i = 2
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
log = open(logs_folder + 'latest.log', 'a')
|
||||
open(logs_folder + 'latest.log', 'a').close()
|
||||
except:
|
||||
try:
|
||||
makedirs(logs_folder, exist_ok=True)
|
||||
log = open(logs_folder + 'latest.log', 'a')
|
||||
open(logs_folder + 'latest.log', 'a').close()
|
||||
except:
|
||||
pass
|
||||
i += 1
|
||||
|
||||
|
||||
def logWrite(message: str, logs_folder=f"logs{sep}", level="INFO") -> None:
|
||||
|
Reference in New Issue
Block a user