圆月山庄资源网 Design By www.vgjia.com
1,不用第三方库
# coding: utf-8 import logging BLACK, 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 } class ColoredFormatter(logging.Formatter): def __init__(self, msg, use_color=True): logging.Formatter.__init__(self, msg) self.use_color = use_color def format(self, record): levelname = record.levelname message = str(record.msg) funcName = record.funcName if self.use_color and levelname in COLORS: levelname_color = COLOR_SEQ % (30 + COLORS[levelname]) + levelname + RESET_SEQ message_color = COLOR_SEQ % (30 + COLORS[levelname]) + message + RESET_SEQ funcName_color = COLOR_SEQ % (30 + COLORS[levelname]) + funcName + RESET_SEQ record.levelname = levelname_color record.msg = message_color record.funcName = funcName_color return logging.Formatter.format(self, record) LOGFORMAT = "[%(asctime)s][%(name)s] [%(levelname)s] (%(filename)s:%(funcName)s:%(lineno)d) %(message)s" LOG_LEVEL = logging.DEBUG formatter = ColoredFormatter(LOGFORMAT) stream = logging.StreamHandler() stream.setLevel(LOG_LEVEL) stream.setFormatter(formatter) logging.root.setLevel(LOG_LEVEL) log = logging.getLogger('logconfig') log.setLevel(LOG_LEVEL) log.addHandler(stream) def Logging(name): log = logging.getLogger(name) log.setLevel(LOG_LEVEL) log.addHandler(stream) return log if __name__ == '__main__': logger = Logging(__name__) logger.info(123123) logger.debug(123123) logger.error(123123) logger.warning(123123)
2,使用colorlog pip install colorlog
# coding: utf-8 # coding: utf-8 from colorlog import ColoredFormatter import logging LOG_LEVEL = logging.DEBUG LOGFORMAT = "[%(asctime)s][%(name)s] [%(log_color)s**%(levelname)s**%(reset)s] [%(filename)s:%(funcName)s:%(log_color)s%(lineno)d%(reset)s] %(log_color)s%(message)s%(reset)s" logging.root.setLevel(LOG_LEVEL) formatter = ColoredFormatter(LOGFORMAT) stream = logging.StreamHandler() stream.setLevel(LOG_LEVEL) stream.setFormatter(formatter) log = logging.getLogger('logconfig') log.setLevel(LOG_LEVEL) log.addHandler(stream) def Logging(name): log = logging.getLogger(name) log.setLevel(LOG_LEVEL) log.addHandler(stream) return log if __name__ == '__main__': logging = Logging("test") logging.info(123123) logging.warning(123123) logging.debug(123123)
3,华丽的日志
pip install logbook termcc dataclasses
#coding: utf-8 from logbook import Logger from termcc.helper.logger import sample_flask as setup_logger setup_logger() logging = Logger(__name__) logging.info("123123") logging.debug("123123") logging.warn("123123")
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年11月01日
2024年11月01日
- 群星《时光正好 电视剧影视原声带》[FLAC/分轨][234.11MB]
- 英雄联盟s14韩国队种子怎么排名 s14韩国队种子队伍排名一览
- 英雄联盟s14四强开始时间 英雄联盟s14四强赛程表一览
- 英雄联盟s14四强赛在哪举办 英雄联盟s14半决赛举办地点一览
- 《三国志8重制版》全女将一览
- 《英雄联盟》Faker第七次晋级决赛
- 《历史时代3》下载方法
- EchoVocalEnsemble-Innocence(2024)[WAV]
- BuceadorVoltio-Satelite(2024)[24-48]FLAC
- VilmPribyl-SmetanaDalibor(2024)[24Bit-WAV]
- 高通骁龙8至尊版亮相:性能领先A18 Pro达到40%,更有多项首发
- 2024骁龙峰会:自研Oryon CPU登陆手机、汽车丨骁龙8至尊版、骁龙至尊版汽车平台
- 稀有度拉满!首款小马宝莉背卡引爆网络热梗
- 群星《全糖少爷1 影视原声带》[320K/MP3][98.36MB]
- 群星《全糖少爷1 影视原声带》[FLAC/分轨][420.97MB]