我的logging.config文件中有以下设置
||
但仍然在终端输出不是颜色
答案 0 :(得分:0)
我尝试了您的颜色格式设置,看来您的代码运行得很好
formatert = "%(log_color)s[%(log_color)s%(asctime)s] %(log_color)s%(filename)s [line: %(log_color)s%(lineno)d] : %(log_color)s%(message)s%(reset)s"
logger = colorlog.getLogger('')
colored_handler = colorlog.StreamHandler()
colored_handler.setFormatter(colorlog.ColoredFormatter( \
formatert,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
},))
logger.setLevel(logging.DEBUG)
logger.addHandler(colored_handler)
logger.log(logging.DEBUG, "DEBUG message")
logger.log(logging.INFO, "INFO message")
logger.log(logging.WARNING, "WARNING message")
logger.log(logging.ERROR, "ERROR message")
logger.log(logging.CRITICAL, "CRITICAL message")