-
Notifications
You must be signed in to change notification settings - Fork 2
/
configuration.py
executable file
·106 lines (78 loc) · 4.27 KB
/
configuration.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# version 1.2.3
import logging
# use with locals()
# debug level messages
formatter_debug = logging.Formatter(
'{\"time\": \"%(asctime)s\", \"file\": \"%(filename)s\", \"func\": \"%(funcName)s\", \"level\": \"%(levelname)s\", \"line\": %(lineno)d, \"module\": \"%(module)s\", \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": \"%(name)s\", \"path\": \"%(pathname)s\", \"procID\": %(process)d, \"proc\": \"%(processName)s\", \"threadID\": %(thread)d, \"thread\": \"%(threadName)s\"}')
# informatin level messages
formatter_info = logging.Formatter(
'{\"time\": \"%(asctime)s\", \"msecs\": %(msecs)d, \"msg\":{ %(message)s }}')
formatter_info_start = logging.Formatter(
'{\"time\": %(asctime)s, \"file\": %(filename)s, \"func\": %(funcName)s, \"level\": %(levelname)s, \"module\": %(module)s, \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": %(name)s}')
formatter_info_end = logging.Formatter(
'{\"time\": %(asctime)s, \"file\": %(filename)s, \"func\": %(funcName)s, \"level\": %(levelname)s, \"module\": %(module)s, \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": %(name)s}')
# warning
formatter_warn = logging.Formatter(
'{\"time\": \"%(asctime)s\", \"file\": \"%(filename)s\", \"func\": \"%(funcName)s\", \"level\": \"%(levelname)s\", \"line\": %(lineno)d, \"module\": \"%(module)s\", \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": \"%(name)s\", \"path\": \"%(pathname)s\"}')
# error with locals()
formatter_error = logging.Formatter(
'{\"time\": \"%(asctime)s\", \"file\": \"%(filename)s\", \"func\": \"%(funcName)s\", \"level\": \"%(levelname)s\", \"line\": %(lineno)d, \"module\": \"%(module)s\", \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": \"%(name)s\", \"path\": \"%(pathname)s\", \"procID\": %(process)d, \"proc\": \"%(processName)s\", \"threadID\": %(thread)d, \"thread\": \"%(threadName)s\"}')
# fatal error with locals()
formatter_fatal = logging.Formatter(
'{\"time\": \"%(asctime)s\", \"file\": \"%(filename)s\", \"func\": \"%(funcName)s\", \"level\": \"%(levelname)s\", \"line\": %(lineno)d, \"module\": \"%(module)s\", \"msecs\": %(msecs)d, \"msg\":%(message)s, \"logger\": \"%(name)s\", \"path\": \"%(pathname)s\", \"procID\": %(process)d, \"proc\": \"%(processName)s\", \"threadID\": %(thread)d, \"thread\": \"%(threadName)s\"}')
# info config
def logger_info(name, log_file, level=logging.INFO):
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_info)
logger = logging.getLogger(name + '-INFO')
logger.setLevel(level)
logger.addHandler(handler)
return logger
def logger_info_start(name, log_file, level=logging.INFO):
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_info_start)
logger = logging.getLogger(name + '-INFOST')
logger.setLevel(level)
logger.addHandler(handler)
return logger
def logger_info_end(name, log_file, level=logging.INFO):
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_info_end)
logger = logging.getLogger(name + '-INFOND')
logger.setLevel(level)
logger.addHandler(handler)
return logger
# debug config
def logger_debug(name, log_file, level=logging.DEBUG):
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_debug)
logger = logging.getLogger(name + '-DEBUG')
logger.setLevel(level)
logger.addHandler(handler)
return logger
# warn config
def logger_warn(name, log_file, level=logging.WARNING):
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_warn)
logger = logging.getLogger(name + '-WARN')
logger.setLevel(level)
logger.addHandler(handler)
return logger
# error config
def logger_error(name, log_file, level=logging.ERROR):
# type: (object, object, object) -> object
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_error)
logger = logging.getLogger(name + '-ERROR')
logger.setLevel(level)
logger.addHandler(handler)
return logger
# fatal config
def logger_fatal(name, log_file, level=logging.CRITICAL):
# type: (object, object, object) -> object
handler = logging.FileHandler(log_file)
handler.setFormatter(formatter_fatal)
logger = logging.getLogger(name + '-FATAL')
logger.setLevel(level)
logger.addHandler(handler)
return logger