import logging
from logging.handlers import TimedRotatingFileHandler
logger = logging.getLogger('simple_example')
logger.setLevel(logging.INFO)
ch = TimedRotatingFileHandler("test.log", when='D', encoding="utf-8")
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
logger.critical('critical message')