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__) 

使用起來相當爽!哈哈...

 

如果您覺得對您有所幫助,請點擊關注一下唄!謝謝!

 

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