zoukankan      html  css  js  c++  java
  • python的logging.config使用详解

        python的log模块是日常使用最多的模块之一,  简单的使用这里就不多说了,见(http://blog.csdn.net/jianhong1990/article/details/17475717)。

        实际运用中,我们可能需要将日志的配置信息独立出来,这时候我们就需要用到logging的另一个功能:

    test.py

    # test.py
    import logging
    import logging.config
    
    logging.config.fileConfig("logging.conf")
    
    #create logger
    logger = logging.getLogger("example")
    
    #"application" code
    logger.debug("debug message")
    logger.info("info message")
    logger.warn("warn message")
    logger.error("error message")
    logger.critical("critical message")
    
    logHello = logging.getLogger("hello")
    logHello.info("Hello world!")
    


    logging.conf配置文件:

    [loggers]
    keys=root,example
    
    [handlers]
    keys=consoleHandler,rotateFileHandler,rootFileHandler
    
    [formatters]
    keys=simpleFormatter
    
    [formatter_simpleFormatter]
    format=[%(asctime)s](%(levelname)s)%(name)s : %(message)s
    
    [logger_root]
    level=DEBUG
    handlers=consoleHandler,rootFileHandler
    
    [logger_example]
    level=DEBUG
    handlers=consoleHandler,rotateFileHandler
    #在app中应用这个log的名字
    qualname=example
    #是否会传递到更高级的logger中,类似于冒泡,会传递到父logger中
    propagate=0
    
    
    [handler_consoleHandler]
    class=StreamHandler
    level=DEBUG
    formatter=simpleFormatter
    args=(sys.stdout,)
    
    [handler_rotateFileHandler]
    class=handlers.RotatingFileHandler
    level=DEBUG
    formatter=simpleFormatter
    args=('logs/cdnlog/test.log', 'a', 200000, 9)
    
    [handler_rootFileHandler]
    class=handlers.RotatingFileHandler
    level=DEBUG
    formatter=simpleFormatter
    args=('logs/cdnlog/root.log', 'a', 200000, 9)

     

  • 相关阅读:
    30 algorithm questions study
    Binary Tree: Write a function to return count of nodes in binary tree which has only one child.
    分布式排序
    android开发中,工程前面有感叹号的解决办法
    android导入工程出现红色感叹号
    INSTALL_FAILED_MISSING_SHARED_LIBRARY错误解决方法
    安卓手机铃声怎么设置
    如何开启Mysql远程访问
    android 链接mysql数据库
    android 连接mysql数据库问题
  • 原文地址:https://www.cnblogs.com/chenjianhong/p/4144957.html
Copyright © 2011-2022 走看看