-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.py
69 lines (62 loc) · 2.1 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
69
import logging
from logging.config import dictConfig
from decouple import config
__all__ = ['logger']
log_level = 'DEBUG' if config('DEBUG', cast=bool) else 'INFO'
dictConfig(
{
'version': 1,
'formatters': {
'default': {
'format': '[%(asctime)s: %(levelname)s] %(filename)s:%(lineno)d: %(message)s',
}},
'handlers': {
'email': {
'class': "utils.logging_handlers.MailAdminHandler",
'level': 'ERROR',
'mailhost': (config('LOGGER_EMAIL_HOST'), config('LOGGER_EMAIL_PORT')),
'fromaddr': config('LOGGER_EMAIL'),
'toaddrs': config('DEV_EMAILS', cast=lambda v: [s.strip() for s in v.split(',')]),
'subject': '',
'formatter': 'default'
},
'console': {
'class': 'logging.StreamHandler',
'level': log_level,
'formatter': 'default'
},
'root_file': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'level': log_level,
'formatter': 'default',
'filename': 'logs/main.log',
'when': 'midnight',
'backupCount': 100,
},
'webhooks_file': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'level': log_level,
'formatter': 'default',
'filename': 'logs/webhooks.log',
'when': 'midnight',
'backupCount': 100,
}
},
'loggers': {
'': {
'level': log_level,
'handlers': ['console', 'root_file', 'email']
},
'bot': {
'level': log_level,
'handlers': ['console', 'root_file', 'email']
},
'werkzeug': {
'level': log_level,
'handlers': ['console', 'webhooks_file', 'email'],
'qualname': 'werkzeug'
}
}
}
)
logger = logging.getLogger('bot')