-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLogger.py
58 lines (45 loc) · 1.65 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
#!/bin/python
import logging;
import sys;
project_name = "multilabel";
instance = logging.getLogger(project_name);
instance.setLevel(logging.INFO);
handler = logging.StreamHandler(sys.stderr);
handler.setLevel(logging.INFO);
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s");
handler.setFormatter(formatter);
instance.addHandler(handler);
def initlog(opts):
global instance;
global handler;
global project_name;
print opts;
if "project_name" in opts:
project_name = opts["project_name"];
print "in Logger", project_name;
instance.removeHandler(handler);
instance = logging.getLogger(project_name);
#set longer
if "logfile" in opts:
handler = logging.FileHandler(opts["logfile"]);
else:
handler = logging.StreamHandler(sys.stderr);
#set formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s");
handler.setFormatter(formatter);
##set level
instance.setLevel(logging.INFO);
if "level" in opts:
if "notset" == opts["level"].lowcase():
instance.setLevel(logging.NOTSET)
elif "debug" == opts["level"].lowcase():
instance.setLevel(logging.DEBUG)
elif "info" == opts["level"].lowcase():
instance.setLevel(logging.INFO)
elif "warning" == opts["level"].lowcase():
instance.setLevel(logging.WARNING)
elif "error" == opts["level"].lowcase():
instance.setLevel(logging.ERROR)
elif "critical" == opts["level"].lowcase():
instance.setLevel(logging.critical)
instance.addHandler(handler);