-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
29 lines (25 loc) · 937 Bytes
/
Copy pathlog.py
File metadata and controls
29 lines (25 loc) · 937 Bytes
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
# log_config.py
import logging
from colorama import Fore, Style, init
init(autoreset=True)
# need to change TODO
class ColorFormatter(logging.Formatter):
def format(self, record):
msg = super().format(record)
if record.levelno == logging.INFO:
return Fore.GREEN + msg + Style.RESET_ALL
elif record.levelno == logging.ERROR:
return Fore.RED + msg + Style.RESET_ALL
elif record.levelno == logging.WARNING:
return Fore.YELLOW + msg + Style.RESET_ALL
return msg
def get_logger(name: str, level=logging.INFO):
logger = logging.getLogger(name)
logger.setLevel(level)
if not logger.hasHandlers():
handler = logging.StreamHandler()
formatter = ColorFormatter("%(levelname)s - %(name)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.propagate = False
return logger