python的logging配置文件,支持logger全局所有文件日志输出

python的日志配置文件,支持写入到文件和控制台;支持滚动覆盖。

version: 1
disable_existing_loggers: False
formatters:
  simple:
    format: "%(asctime)s %(levelname)-8s [%(threadName)s] %(name)s %(filename)s: %(lineno)d: %(message)s"
handlers:
  console:
    class: logging.StreamHandler
    level: INFO
    formatter: simple
  file:
    class: logging.handlers.TimedRotatingFileHandler
    filename: ./logs/application.log
    level: INFO
    formatter: simple
    encoding: UTF-8
    when: d
    interval: 1
    backupCount: 30
root:
  level: INFO
  handlers: [file,console]
logging_config_file = './conf/logging_config.yaml'

# 设置日志
with open(logging_config_file, 'r') as f:
    config = yaml.safe_load(f.read())
    logging.config.dictConfig(config)
logger = logging.getLogger(__name__) 

使用起来相当爽!哈哈...

 

如果您觉得对您有所帮助,请点击关注一下呗!谢谢!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章