-
Notifications
You must be signed in to change notification settings - Fork 5
/
logger_settings.py
44 lines (40 loc) · 1.16 KB
/
logger_settings.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
import sys,os
import logging
from logging.config import dictConfig
logging_config = dict(
version=1,
formatters={
'verbose': {
'format': ("[%(asctime)s] %(levelname)s "
"[%(name)s:%(lineno)s] %(message)s"),
'datefmt': "%d/%b/%Y %H:%M:%S",
},
'simple': {
'format': '%(levelname)s %(message)s',
},
},
handlers={
'logger': {'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'level': logging.DEBUG,
'filename': 'log/message.log',
'maxBytes': 52428800,
'backupCount': 7},
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'simple',
'stream': sys.stdout,
},
},
loggers={
'logger': {
'handlers': ['logger', 'console'],
'level': logging.DEBUG
},
}
)
if not os.path.exists('log'):
os.makedirs('log')
dictConfig(logging_config)
logger = logging.getLogger('logger')