-
Notifications
You must be signed in to change notification settings - Fork 55
/
log.py
60 lines (36 loc) · 1.15 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
53
54
55
56
57
58
59
60
import sys
import logging
from config import Config
level = logging.INFO
TRACE = 9
l = logging.getLogger("ABOOTOOL")
con = logging.StreamHandler(sys.stderr)
con.setFormatter(logging.Formatter('%(levelname)1s: %(message)s'))
con.setLevel(level)
logfile = logging.FileHandler(Config.log_file)
logfile.setFormatter(logging.Formatter('%(asctime)-15s %(levelname)5s: %(message)s'))
logfile.setLevel(logging.DEBUG)
l.addHandler(con)
l.addHandler(logfile)
l.setLevel(TRACE)
logging.addLevelName(TRACE, "TRACE")
def adjustLevels():
for log in logging.Logger.manager.loggerDict:
l.setLevel(logging.CRITICAL)
for h in logging.root.handlers:
logging.root.removeHandler(h)
l.setLevel(TRACE)
def setVerbose(more = False):
global level
level = more and TRACE or logging.DEBUG
logfile.setLevel(level)
def I(msg, *kargs, **kwargs):
l.info(msg, *kargs, **kwargs)
def D(msg, *kargs, **kwargs):
l.debug(msg, *kargs, **kwargs)
def T(msg, *kargs, **kwargs):
l.log(TRACE, msg, *kargs, **kwargs)
def W(msg, *kargs, **kwargs):
l.warn(msg, *kargs, **kwargs)
def E(msg, *kargs, **kwargs):
l.error(msg, *kargs, **kwargs)