-
Notifications
You must be signed in to change notification settings - Fork 24
/
util.py
44 lines (36 loc) · 1.03 KB
/
util.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
""" Utilities """
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# Logging
# =======
import logging
from colorlog import ColoredFormatter
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = ColoredFormatter(
"%(log_color)s[%(asctime)s] %(message)s",
# datefmt='%H:%M:%S.%f',
datefmt=None,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'white,bold',
'INFOV': 'cyan,bold',
'WARNING': 'yellow',
'ERROR': 'red,bold',
'CRITICAL': 'red,bg_white',
},
secondary_log_colors={},
style='%'
)
ch.setFormatter(formatter)
log = logging.getLogger('rn')
log.setLevel(logging.DEBUG)
log.handlers = [] # No duplicated handlers
log.propagate = False # workaround for duplicated logs in ipython
log.addHandler(ch)
logging.addLevelName(logging.INFO + 1, 'INFOV')
def _infov(self, msg, *args, **kwargs):
self.log(logging.INFO + 1, msg, *args, **kwargs)
logging.Logger.infov = _infov