-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.py
68 lines (52 loc) · 1.48 KB
/
logger.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
61
62
63
64
65
66
67
68
import logging
import sys
import os
addedfiles = set()
def addLogFile(file):
if file in addedfiles:
return
addedfiles.add(file)
sh = logging.StreamHandler(open(logdir+'/'+file,'w'))
sh.setLevel(logging.INFO)
sh.setFormatter(formatter)
dlog.addHandler(sh)
logdir = os.path.expanduser("~") + '/logs'
DL = 1
if not os.path.exists(logdir):
os.mkdir(logdir)
# log = logging.getLogger("mainLogger")
# log.setLevel(logging.INFO)
dlog = logging.getLogger("logLogger")
dlog.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s : %(message)s')
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.INFO)
sh.setFormatter(formatter)
dlog.addHandler(sh)
sh = logging.StreamHandler(open(logdir+'/err.log','w'))
sh.setLevel(logging.INFO)
sh.setFormatter(formatter)
dlog.addHandler(sh)
sh = logging.StreamHandler(open(logdir+'/allerr.log','a'))
sh.setLevel(logging.INFO)
sh.setFormatter(formatter)
dlog.addHandler(sh)
def __fmt(*args):
if issubclass(type(args), list) \
or issubclass(type(args), tuple):
return ' '.join([str(x) for x in args])
else:
return args
def printl(*args):
dlog.info(__fmt(*args))
def printd(*args):
dlog.info(__fmt(*args))
def printe(*args):
dlog.error(__fmt(*args))
def stacktrace(msg, *args, **kwargs):
try:
msg += '(%r, %r)' %(args, kwargs)
dlog.exception(msg)
except:
printe('Error formatting stack msg')
dlog.exception(msg)