Logging made better part 2
This commit is contained in:
@@ -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)
|
Reference in New Issue
Block a user