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

python之logging模块

时间:2017-09-23 18:53:00      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:blog   config   level   dha   process   code   aaa   mod   logging   

from logging import *
import sys


def main():
    basicConfig(level=WARNING,
                stream=sys.stdout,
                # filename=‘log.log‘,
                # filemode=‘a‘,
                format=%(asctime)s\t%(filename)s\t%(lineno)d\t%(message)s\t%(levelname)s\t
                       %(pathname)s\t%(module)s\t%(name)s\t%(funcName)s\t%(created)f\t
                       %(relativeCreated)d\t%(thread)d\t%(threadName)s\t%(process)d,
                datefmt=%Y %m %d %H:%M:%S  %a %b)
    debug(aaa debug)
    info(bbb info)
    warn(ccc warn)
    warning(ccc warning)
    error(ddd error)
    critical(critical)
    fatal(fatal)


def main2():
    format1 = %(asctime)s\t%(filename)s\t%(lineno)d\t%(message)s\t%(levelname)s\t               %(pathname)s\t%(module)s\t%(name)s\t%(funcName)s\t%(created)f\t               %(relativeCreated)d\t%(thread)d\t%(threadName)s\t%(process)d
    # basicConfig(level=WARNING,
    #             stream=sys.stdout,
    #             # filename=‘log.log‘,
    #             # filemode=‘a‘,
    #             format=format,
    #             datefmt=‘%Y %m %d %H:%M:%S  %a %b‘)
    logger = getLogger(xxx)
    logger.setLevel(DEBUG)
    stream_handler = StreamHandler()
    stream_handler.setLevel(DEBUG)
    file_handler = FileHandler(log2.log)
    file_handler.setLevel(DEBUG)
    formatter = Formatter(fmt=format1, datefmt=%Y %m %d %H:%M:%S  %a %b)
    stream_handler.setFormatter(formatter)
    file_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    logger.addHandler(file_handler)

    logger.debug(aaa debug)
    logger.info(bbb info)
    logger.warn(ccc warn)
    logger.warning(ccc warning)
    logger.error(ddd error)
    logger.critical(critical)
    logger.fatal(fatal)


# main2()
def main3():
    error(llllllllll)
main3()
"""
CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0
"""

 

python之logging模块

标签:blog   config   level   dha   process   code   aaa   mod   logging   

原文地址:http://www.cnblogs.com/zhaoxianglong1987/p/7581623.html

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