小编afm*_*one的帖子

Python3 日志 yaml 配置

我是python的新手。我正在尝试导入 yaml 中定义的日志记录配置。我得到错误:

Traceback (most recent call last):
  File "D:/python_3/db_interact/dbInteract.py", line 200, in <module>
    logging.config.fileConfig('conf/logging.yaml')
  File "C:\Programs\Python\Python36\lib\logging\config.py", line 74, in fileConfig
    cp.read(fname)
  File "C:\Programs\Python\Python36\lib\configparser.py", line 697, in read
    self._read(fp, filename)
  File "C:\Programs\Python\Python36\lib\configparser.py", line 1080, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: 'conf/logging.yaml', line: 1
'version: 1\n'
Run Code Online (Sandbox Code Playgroud)

我使用以下方法导入配置:

logging.config.fileConfig('conf/logging.yaml')
Run Code Online (Sandbox Code Playgroud)

我的配置是:

version: 1
disable_existing_loggers: true
formatters:
  simple:
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
  console:
    class: logging.StreamHandler
    level: INFO
    formatter: simple
    stream: ext://sys.stdout
  file: …
Run Code Online (Sandbox Code Playgroud)

configuration logging yaml python-3.x

4
推荐指数
1
解决办法
6295
查看次数

标签 统计

configuration ×1

logging ×1

python-3.x ×1

yaml ×1