快活林资源网 Design By www.csstdc.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.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com
暂无评论...
更新日志
2024年12月23日
2024年12月23日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]