-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator_log.py
37 lines (35 loc) · 1.14 KB
/
generator_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
import logging
logger = logging.getLogger('scarlettlogger')
try:
from colorlog import ColoredFormatter
from gettext import gettext as _
"""Return a logger with a default ColoredFormatter."""
formatter = ColoredFormatter(
"(%(threadName)-9s) %(log_color)s%(levelname)-8s%(reset)s (%(funcName)-5s) %(message_log_color)s%(message)s",
datefmt=None,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red',
},
secondary_log_colors={
'message': {
'ERROR': 'red',
'CRITICAL': 'red',
'DEBUG': 'yellow',
'INFO': 'yellow,bg_blue'
}
},
style='%'
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
except ImportError:
# No color available, use default config
logging.basicConfig(format='%(levelname)s: %(message)s')
logger.warn("Disabling color, you really want to install colorlog.")