-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
33 lines (29 loc) · 949 Bytes
/
Logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from utils import get_now_date
class Log:
def __init__(self, log_file_path):
logging.basicConfig(filename=log_file_path, format='%(levelname)s - %(message)s', level=logging.INFO)
def log(self, msg:str, level="info", print_log=True) -> None:
#TODO add more log levels like debug, warn , critical ...etc
level = level.lower()
msg = f'{get_now_date()} - {msg}'
# print(msg, level)
if level=="info":
logging.info(msg)
elif level == "error":
logging.error(msg)
elif level == "warn" or level == "warning":
logging.warning(msg)
elif level == 'critical':
logging.critical(msg)
elif level == 'debug':
logging.debug(msg)
else:
print ("unknown level, will default to info")
logging.warning("Passed error level is not good, will use info level to print next log entry")
logging.info(msg)
if print_log:
print(msg)
def exit(self):
self.log("Exiting", print_log=True)
logging.shutdown()