Add logging

This commit is contained in:
William Valentin
2025-07-20 13:05:29 -07:00
parent b9a9742f3b
commit 2b6b607ac4
3 changed files with 87 additions and 0 deletions

35
src/init.py Normal file
View File

@@ -0,0 +1,35 @@
import os
from logger import init_logger
from constants import LOG_PATH, LOG_CLEAR, LOG_LEVEL
if not os.path.exists(LOG_PATH):
os.mkdir(LOG_PATH)
else:
pass
log_files = (
f"{LOG_PATH}/app.log",
f"{LOG_PATH}/app.warning.log",
f"{LOG_PATH}/app.error.log",
)
if LOG_LEVEL == "DEBUG":
testing_mode = True
else:
testing_mode = False
logger = init_logger(__name__, testing_mode=testing_mode)
if LOG_CLEAR == "True":
try:
for log_file in log_files:
if os.path.exists(log_file):
with open(log_file, "r+") as t:
t.truncate(0)
else:
pass
except Exception as e:
logger.error(e)
raise
else:
pass