码迷,mamicode.com
首页 > 编程语言 > 详细

python logging colorlog

时间:2016-12-21 21:17:29      阅读:935      评论:0      收藏:0      [点我收藏+]

标签:time   pytho   hand   res   nbsp   span   dev   日志   .com   

 1 import logging
 2 LOG_LEVEL = logging.NOTSET
 3 LOGFORMAT = "[%(log_color)s%(levelname)s] [%(log_color)s%(asctime)s] %(log_color)s%(filename)s [line:%(log_color)s%(lineno)d] : %(log_color)s%(message)s%(reset)s"
 4 import colorlog
 5 logging.root.setLevel(LOG_LEVEL)
 6 ############
 7 #此配置是将日志输出到myapp.log
 8 colorlog.basicConfig(format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s, filename=myapp.log,
 9                 filemode=w, datefmt=%a, %d %b %Y %H:%M:%S, )
10 ##############
11 formatter = colorlog.ColoredFormatter(LOGFORMAT)
12 stream = logging.StreamHandler()
13 stream.setLevel(LOG_LEVEL)
14 stream.setFormatter(formatter)
15 log = logging.getLogger()
16 log.setLevel(LOG_LEVEL)
17 log.addHandler(stream)
18 log.debug("A quirky message only developers care about")
19 log.info("Curious users might want to know this")
20 log.warn("Something is wrong and any user should be informed")
21 log.error("Serious stuff, this is red for a reason")
22 log.critical("OH NO everything is on fire")
23 #####################################
技术分享

 

python logging colorlog

标签:time   pytho   hand   res   nbsp   span   dev   日志   .com   

原文地址:http://www.cnblogs.com/danny-chen/p/6208666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!