2016-05-10 20:23:48 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-12-14 15:27:20 -06:00
|
|
|
import os
|
2016-05-10 20:23:48 -05:00
|
|
|
import logging
|
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
import paths
|
|
|
|
import sys
|
|
|
|
|
|
|
|
APP_LOG_FILE = 'debug.log'
|
|
|
|
ERROR_LOG_FILE = "error.log"
|
2019-01-01 19:42:53 -06:00
|
|
|
MESSAGE_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"
|
|
|
|
DATE_FORMAT = "%d/%m/%Y %H:%M:%S"
|
2016-05-10 20:23:48 -05:00
|
|
|
|
2019-01-01 19:42:53 -06:00
|
|
|
formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
|
2016-05-10 20:23:48 -05:00
|
|
|
|
|
|
|
requests_log = logging.getLogger("requests")
|
|
|
|
requests_log.setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
#handlers
|
|
|
|
|
2019-01-01 19:42:53 -06:00
|
|
|
app_handler = RotatingFileHandler(os.path.join(paths.logs_path(), APP_LOG_FILE), mode="w", encoding="utf-8")
|
2016-05-10 20:23:48 -05:00
|
|
|
app_handler.setFormatter(formatter)
|
|
|
|
app_handler.setLevel(logging.DEBUG)
|
|
|
|
logger.addHandler(app_handler)
|
|
|
|
|
2019-01-01 19:42:53 -06:00
|
|
|
error_handler = logging.FileHandler(os.path.join(paths.logs_path(), ERROR_LOG_FILE), mode="w", encoding="utf-8")
|
2016-05-10 20:23:48 -05:00
|
|
|
error_handler.setFormatter(formatter)
|
|
|
|
error_handler.setLevel(logging.ERROR)
|
|
|
|
logger.addHandler(error_handler)
|