【发布时间】:2020-08-06 03:56:35
【问题描述】:
需要帮助, 我想从 pytest.ini 设置我的记录器或为此使用 yaml 文件,一切都很好,除了一件事: 如果仅使用文件名,则在 yaml 或 pytest.ini 中硬编码的日志文件的文件夹,在这种情况下,我的日志文件保存在测试文件夹中,但我需要将我的日志保存在我的自定义文件夹中。
我不想覆盖我的设置文件。
yaml文件的读取方法
with open(f'{get_root_path()}\logging.yaml', 'r') as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
yaml
info_file_handler:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: standard
filename: folder info.log
maxBytes: 10485760 # 10MB
backupCount: 20
encoding: utf8
pytest.ini
[pytest]
log_cli = 1
log_cli_level = DEBUG
log_cli_format = %(asctime)s [%(levelname)8s] %(name)s %(message)s (%(filename)s:%(lineno)s)
log_name = test
log_file = pytest.log
log_file_level = DEBUG
log_file_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_file_date_format=%Y-%m-%d %H:%M:%S
谢谢。
【问题讨论】:
标签: python-3.x logging pytest