forked from angr/angr-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandard_logging.py
31 lines (23 loc) · 880 Bytes
/
standard_logging.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
#!/usr/bin/python
import logging
logging.basicConfig(format='%(levelname)-7s | %(asctime)-23s | %(name)-8s | %(message)s', level=logging.WARNING)
logging.getLogger("main").setLevel(logging.DEBUG)
color_name = True
color_msg = True
original_emit = logging.StreamHandler.emit
def emit_wrap(*args, **kwargs):
#import ipdb; ipdb.set_trace()
record = args[1]
color = hash(record.name) % 8 + 30
if color_name:
try:
record.name = ("\x1b[%dm" % color) + record.name + "\x1b[0m"
except Exception:
pass
if color_msg:
try:
record.msg = ("\x1b[%dm" % color) + record.msg + "\x1b[0m"
except Exception:
pass
original_emit(*args, **kwargs)
logging.StreamHandler.emit = emit_wrap