2023-03-10 08:43:18 -05:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
def getlogger():
|
|
|
|
# create a custom logger
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
# create handlers
|
|
|
|
warn_handler = logging.StreamHandler()
|
2023-04-10 07:37:43 -04:00
|
|
|
info_handler = logging.StreamHandler()
|
2023-03-10 08:43:18 -05:00
|
|
|
error_handler = logging.FileHandler('bot.log', mode='a')
|
|
|
|
warn_handler.setLevel(logging.WARNING)
|
|
|
|
error_handler.setLevel(logging.ERROR)
|
2023-04-10 07:37:43 -04:00
|
|
|
info_handler.setLevel(logging.INFO)
|
2023-03-10 08:43:18 -05:00
|
|
|
|
|
|
|
# create formatters
|
2023-04-11 01:42:43 -04:00
|
|
|
warn_format = logging.Formatter(
|
|
|
|
'%(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
|
|
|
error_format = logging.Formatter(
|
|
|
|
'%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
|
2023-04-10 07:37:43 -04:00
|
|
|
info_format = logging.Formatter('%(message)s')
|
2023-03-10 08:43:18 -05:00
|
|
|
|
|
|
|
# set formatter
|
|
|
|
warn_handler.setFormatter(warn_format)
|
|
|
|
error_handler.setFormatter(error_format)
|
2023-04-10 07:37:43 -04:00
|
|
|
info_handler.setFormatter(info_format)
|
2023-03-10 08:43:18 -05:00
|
|
|
|
|
|
|
# add handlers to logger
|
|
|
|
logger.addHandler(warn_handler)
|
|
|
|
logger.addHandler(error_handler)
|
2023-04-10 07:37:43 -04:00
|
|
|
logger.addHandler(info_handler)
|
2023-03-10 08:43:18 -05:00
|
|
|
|
|
|
|
return logger
|