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

python logging 日志模块的配置和使用

时间:2015-08-29 12:29:08      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

import logging
logging.basicConfig(level=logging.DEBUG,
                    format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s,
                    datefmt=%a, %d %b %Y %H:%M:%S,
                    filename=/tmp/test.log,
                    filemode=w)

logging.debug(debug message)
logging.info(info message)
logging.warning(warning message)
logging.error(error message)
logging.critical(critical message)
 
import logging

# 设置root logger
r = logging.getLogger()
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(%(asctime)s - %(levelname)s - %(message)s)
ch.setFormatter(formatter)
r.addHandler(ch)

# 创建一个logger作为父亲
p = logging.getLogger(foo)
p.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(%(asctime)s - %(message)s)
ch.setFormatter(formatter)
p.addHandler(ch)

# 创建一个孩子logger
c = logging.getLogger(foo.bar)
c.debug(foo)  

技术分享

python logging 日志模块的配置和使用

标签:

原文地址:http://www.cnblogs.com/jkmiao/p/4768740.html

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