-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog_config.py
59 lines (49 loc) · 1.44 KB
/
log_config.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
from logging import Handler
from telegram import Bot
class TelegramLogsHandler(Handler):
def __init__(self, telegram_token, chat_id):
super().__init__()
self.chat_id = chat_id
self.bot = Bot(telegram_token)
def emit(self, record):
log_entry = self.format(record)
self.bot.send_message(chat_id=self.chat_id, text=log_entry)
ERROR_LOG_FILENAME = "error.log"
LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": "%(asctime)s:c:%(process)d:%(lineno)d " "%(levelname)s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
"simple": {
"format": "%(name)s - %(message)s",
},
},
"handlers": {
"logfile": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"filename": ERROR_LOG_FILENAME,
"formatter": "default",
"backupCount": 2,
},
"verbose_output": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout",
},
},
"loggers": {
"pontus": {
"level": "INFO",
"handlers": [
"verbose_output",
],
'propagate': False
},
},
"root": {"level": "INFO", "handlers": ["logfile", "verbose_output"]},
}