zoukankan      html  css  js  c++  java
  • python logging

    https://www.cnblogs.com/liujiacai/p/7804848.html

    C:WindowsSystem32>pip freeze
    certifi==2018.4.16
    chardet==3.0.4
    Django==2.0.6
    idna==2.7
    PyMySQL==0.8.1
    pytz==2018.4
    PyYAML==3.13
    requests==2.19.1
    selenium==3.13.0
    urllib3==1.23
    xlrd==1.1.0
    xlwt==1.3.0
    pip freeze
    version: 1
    disable_existing_loggers: False
    formatters:
            simple:
                format: "%(asctime)s - %(name)s - %(levelname)s - %(threadName)s - %(lineno)d - %(message)s"
    handlers:
        console:
                class: logging.StreamHandler
                level: DEBUG
                formatter: simple
                stream: ext://sys.stdout
        info_file_handler:
                class: logging.handlers.RotatingFileHandler
                level: INFO
                formatter: simple
                filename: info.log
                maxBytes: 10485760
                backupCount: 20
                encoding: utf8
        error_file_handler:
                class: logging.handlers.RotatingFileHandler
                level: ERROR
                formatter: simple
                filename: errors.log
                maxBytes: 10485760
                backupCount: 20
                encoding: utf8
    loggers:
        my_module:
                level: ERROR
                handlers: [info_file_handler]
                propagate: no
    root:
        level: INFO
        handlers: [console,info_file_handler,error_file_handler]
    yaml
    import yaml
    import logging.config
    import os
    
    def setup_logging(default_path = "logging.yaml",default_level = logging.INFO,env_key = "LOG_CFG"):
        path = default_path
        value = os.getenv(env_key,None)
        if value:
            path = value
        if os.path.exists(path):
            with open(path,"r") as f:
                config = yaml.load(f)
                logging.config.dictConfig(config)
        else:
            logging.basicConfig(level = default_level)
    
    def func():
        logging.info("start func")
    
        logging.info("exec func")
    
        logging.info("end func")
    
    if __name__ == "__main__":
        setup_logging(default_path = "logging.yaml")
        func()
    python code
  • 相关阅读:
    MySQL优化器 limit影响的case
    Innodb物理存储结构系列1
    Innodb 锁系列1 同步机制
    javascript变量作用域 全局及局部
    测试20160422
    python-推荐
    python问题:IndentationError:expected an indented block错误解决
    协同过滤(推荐方法)——数据挖掘
    教你在Excel里做GA的水平百分比图的详细步骤(图文教程)-成为excel大师(1)
    win7搭建ios开发环境
  • 原文地址:https://www.cnblogs.com/xiaodebing/p/9855016.html
Copyright © 2011-2022 走看看