2021
01-13
01-13
python日志通过不同的等级打印不同的颜色(示例代码)
1,不用第三方库#coding:utf-8importloggingBLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE=range(8)RESET_SEQ="\033[0m"COLOR_SEQ="\033[1;%dm"COLORS={'WARNING':GREEN,'INFO':WHITE,'DEBUG':BLUE,'CRITICAL':YELLOW,'ERROR':RED}classColoredFormatter(logging.Formatter):def__init__(self,msg,use_color=True):logging.Formatter.__init__(self,msg)self.use_color=use_colordef...
继续阅读 >