-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
58 lines (47 loc) · 1.65 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""contains LoggingManager class"""
import os
import sys
import logging
from constants import Constants, Messages
class LoggingManager:
"""used for logging and printing"""
def __init__(
self, date: str, folder=Constants.RESULTS_FOLDER, level=logging.DEBUG
) -> None:
path = os.path.join(folder, date)
if not os.path.exists(path):
os.makedirs(path)
logging.basicConfig(
level=level,
filename=os.path.join(path, Constants.LOG_FILE),
filemode="a",
format="%(asctime)s - LOGGING.%(levelname)s - %(message)s",
)
self.logger = logging.getLogger()
def debug(self, msg: str, stdout=True) -> None:
"""logs debug message"""
self.logger.debug(msg)
if stdout:
print(Messages.DEBUG_MSG.format(msg=msg))
def info(self, msg: str, stdout=True) -> None:
"""logs info message"""
self.logger.info(msg)
if stdout:
print(Messages.INFO_MSG.format(msg=msg))
def error(self, msg: str, stdout=True) -> None:
"""logs error message"""
self.logger.error(msg)
if stdout:
print(Messages.ERR_MSG.format(msg=msg))
def critical(self, msg: str, stdout=True) -> None:
"""logs critical message, exits program"""
self.logger.critical(msg)
if stdout:
print(Messages.CRIT_MSG.format(msg=msg))
print(Messages.EXITING)
sys.exit()
def warning(self, msg: str, stdout=True) -> None:
"""logs warning message"""
self.logger.warning(msg)
if stdout:
print(Messages.WARN_MSG.format(msg=msg))