Logging made better part 2

This commit is contained in:
2022-08-11 12:01:31 +02:00
parent 617e14f680
commit dd9ca838f7
5 changed files with 24 additions and 16 deletions

View File

@@ -5,10 +5,10 @@ import shutil
from datetime import datetime
log_size = 512
with open("config.json", "r", encoding='utf8') as file:
log_folder = json.loads(file.read())["locations"]["logs"]
with open(os.getcwd()+os.path.sep+"config.json", "r", encoding='utf8') as file:
json_contents = json.loads(file.read())
log_size = json_contents["logging"]["size"]
log_folder = json_contents["logging"]["location"]
file.close()
# Check latest log size
@@ -26,7 +26,7 @@ def checkSize():
print(f'Copied {os.path.join(log_folder, datetime.now().strftime("%d.%m.%Y_%H:%M:%S"))}.log.gz')
open(os.path.join(log_folder, "latest.log"), 'w').close()
except FileNotFoundError:
print('Not found')
print(f'Log file {os.path.join(log_folder, "latest.log")} does not exist')
pass
# Append string to log
@@ -44,5 +44,5 @@ def logAppend(message):
# Print to stdout and then to log
def logWrite(message):
# save to log file and rotation is to be done
logAppend(f'[{datetime.now().strftime("%d.%m.%Y")}] [{datetime.now().strftime("%H:%M:%S")}] {message}', flush=True)
logAppend(f'{message}')
print(f"{message}", flush=True)