from logzero import LogFormatter, setup_default_logger, logfile, logger
import logging
# 时间格式
data_style = '%Y-%m-%d %H:%M:%S'
# 控制台输出格式
handler_format = '%(color)s[%(asctime)s| %(levelname)s |%(filename)s:%(lineno)d] %(message)s%(end_color)s'
hand_format = LogFormatter(fmt=handler_format, datefmt=data_style)
setup_default_logger(formatter=hand_format)
# 文件输出格式
file_format = '[%(asctime)s| %(levelname)s |%(filename)s:%(lineno)d] %(message)s'
formatter = logging.Formatter(file_format, data_style)
logfile('log/mylog.log', formatter=formatter, maxBytes=1024**2*10, backupCount=3, encoding='utf-8')
# Log some variables
logger.info("var1: %s, var2: %s")
logger.debug("var1: %s, var2: %s")
logger.warning("var1: %s, var2: %s")
logger.error("var1: %s, var2: %s")