forked from shine-jayakumar/insta-likecom-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplogger.py
37 lines (28 loc) · 1.18 KB
/
applogger.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
import logging
from logging.handlers import TimedRotatingFileHandler
from datetime import datetime
import os
import sys
# from constants.constants import LOG_PATH
LOG_PATH = 'logs'
class AppLogger:
def __init__(self, name):
# ====================================================
# Setting up logger
# ====================================================
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.INFO)
logfname = os.path.join(LOG_PATH, f'instalikecombot_{datetime.now().strftime("%Y_%m_%d")}.log')
formatter = logging.Formatter("[%(asctime)s]:[%(name)s]:[%(funcName)s:%(lineno)s]:[%(levelname)s]:%(message)s")
file_handler = TimedRotatingFileHandler(logfname, when='midnight')
file_handler.setFormatter(formatter)
stdout_formatter = logging.Formatter("[*] => %(message)s")
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setFormatter(stdout_formatter)
self.logger.addHandler(file_handler)
self.logger.addHandler(stdout_handler)
def getlogger(self):
"""
Returns the logger object
"""
return self.logger