One - One Code All

Blog Content

python日志logging实例

Python   2010-04-05 21:27:47

logging实例

import logging
import sys

def test_log_level():
    # set default logging configuration
    logger = logging.getLogger()    # initialize logging class
    logger.setLevel(logging.DEBUG)  # default log level
    format = logging.Formatter("%(asctime)s - %(message)s")    # output format 
    sh = logging.StreamHandler(stream=sys.stdout)    # output to standard output
    sh.setFormatter(format)
    logger.addHandler(sh)
    
    # use logging to generate log ouput 
    logger.info("this is info")
    logger.debug("this is debug")
    logger.warning("this is warning")
    logging.error("this is error")
    logger.critical("this is critical")

test_log_level()



上一篇:python内置模块logging
下一篇:python日志系统用logging 代替print

The minute you think of giving up, think of the reason why you held on so long.