彩色日志
import logging
import os
from logging.handlers import RotatingFileHandler
import colorlog
log_colors_config = {
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red',
}
class Log:
def __init__(self, logname: str = 'log.local.log'):
self.logname = logname
self.logger = logging.getLogger()
self.logger.setLevel(logging.DEBUG)
self.formatter = colorlog.ColoredFormatter(
'%(log_color)s[%(asctime)s] [%(filename)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s',
log_colors=log_colors_config)
fh = logging.handlers.TimedRota