介绍
简介
yaml是一个专门用来写配置文件的语言
实例
【analysisyaml.py】
import yaml
import os
LocalPath = os.path.abspath(os.path.dirname(__file__))
configPath = os.path.join(LocalPath,'config.yaml')
with open(configPath,'rt',encoding='utf-8') as cfg:
config = yaml.safe_load(cfg.read())
print(type(config))
print(config)
【config.yaml】
---
version: 1
disable_existing_loggers: False
formatters:
simple:
format: '%(asctime)s %(levelname)-8s %(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: iaasagent.log
maxBytes: 10485760
backupCount: 1
encoding: utf8
error_file_handler:
class: logging.handlers.RotatingFileHandler
level: ERROR
formatter: simple
filename: iaasagent.log
maxBytes: 10485760
backupCount: 0
encoding: utf8
loggers:
my_module:
level: ERROR
handlers: [console]
propagate: no
root:
level: INFO
handlers: [info_file_handler, error_file_handler]