Add logging
This commit is contained in:
35
src/init.py
Normal file
35
src/init.py
Normal 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
|
||||
Reference in New Issue
Block a user