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__)
使用起來相當爽!哈哈...
如果您覺得對您有所幫助,請點擊關注一下唄!謝謝!