-
Notifications
You must be signed in to change notification settings - Fork 2
/
loader.py
71 lines (51 loc) · 1.68 KB
/
loader.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
import logging
from datetime import datetime
from logging.handlers import RotatingFileHandler
import pytz
from aiogram import Bot, Dispatcher
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from controllerBD.add_info_to_db import add_gender_info
from controllerBD.models import create_tables
from data import config
timezone = pytz.timezone('Etc/GMT-3')
def timetz(*args):
return datetime.now(timezone).timetuple()
logger = logging.getLogger('main_logger')
aiogram_logger = logging.getLogger('aio_logger')
schedule_logger = logging.getLogger('schedule')
logger.setLevel(logging.INFO)
aiogram_logger.setLevel(logging.INFO)
schedule_logger.setLevel(level=logging.DEBUG)
main_handler = RotatingFileHandler(
'logs/my_logger.log',
maxBytes=30000000,
backupCount=5,
)
aiogram_handler = RotatingFileHandler(
'logs/aiogram_logger.log',
maxBytes=30000000,
backupCount=2,
)
schedule_handler = RotatingFileHandler(
'logs/schedule_logger.log',
maxBytes=30000000,
backupCount=2,
)
logger.addHandler(main_handler)
aiogram_logger.addHandler(aiogram_handler)
schedule_logger.addHandler(schedule_handler)
formatter = logging.Formatter(
fmt=('%(asctime)s.%(msecs)d %(levelname)s '
'%(filename)s %(funcName)s %(message)s'),
datefmt='%d-%m-%Y %H:%M:%S',
)
formatter.converter = timetz
main_handler.setFormatter(formatter)
aiogram_handler.setFormatter(formatter)
schedule_handler.setFormatter(formatter)
bot = Bot(token=str(config.TOKEN))
dp = Dispatcher(bot, storage=MemoryStorage())
dp.middleware.setup(LoggingMiddleware(logger=aiogram_logger))
create_tables()
add_gender_info()