-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
52 lines (35 loc) · 1.27 KB
/
log.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
import logging
import colorama
from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL
colormap = {
'DEFAULT' : colorama.Fore.RESET,
'INFO' : colorama.Fore.WHITE,
'DEBUG' : colorama.Fore.LIGHTBLACK_EX,
'WARNING': colorama.Fore.YELLOW,
'ERROR' : colorama.Fore.RED,
'CRITICAL' : colorama.Fore.RED,
'SPECIAL' : colorama.Fore.CYAN
}
LOGPATH = 'logs/audio_modem.log'
def debug(msg):
logging.debug(f"{colormap.get('DEBUG', '')}{msg}")
def info(msg):
logging.info(f"{colormap.get('INFO', '')}{msg}")
def special(msg):
logging.info(f"{colormap.get('SPECIAL', '')}{msg}")
def error(msg):
logging.error(f"{colormap.get('ERROR', '')}{msg}")
def warning(msg):
logging.warning(f"{colormap.get('WARNING', '')}{msg}")
logFormatter = logging.Formatter(
colormap['DEFAULT'] + "%(asctime)s [%(levelname)-s] %(message)s", "%H:%M:%S")
rootLogger = logging.getLogger()
rootLogger.setLevel(DEBUG)
# fileHandler = logging.FileHandler(LOGPATH)
# fileHandler.setFormatter(logFormatter)
# rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
consoleHandler.setLevel(DEBUG)
info("#####################################################")