forked from just-an-dev/sodogetip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_logger.py
29 lines (22 loc) · 1.13 KB
/
bot_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
import logging
import os
from datetime import date
from logging.handlers import RotatingFileHandler
from config import DATA_PATH, bot_config
if not os.path.exists(DATA_PATH + bot_config['logs_path']):
os.makedirs(DATA_PATH + bot_config['logs_path'])
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('prawcore').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
formatter_file = logging.Formatter('%(asctime)s :: (%(threadName)-11s) :: (%(levelname)-10s) :: %(name)s :: %(pathname)s:%(lineno)s :: %(message)s')
formatter_output = logging.Formatter('%(asctime)s - (%(threadName)-11s) - (%(levelname)-10s) - %(message)s')
file_handler = RotatingFileHandler(DATA_PATH + bot_config['logs_path'] + 'activity_' + date.today().strftime('%d%m%Y') + '.log', 'a', 1000000, 1)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter_file)
logger.addHandler(file_handler)
steam_handler = logging.StreamHandler()
steam_handler.setLevel(logging.DEBUG)
steam_handler.setFormatter(formatter_output)
logger.addHandler(steam_handler)