在行为驱动的框架中,我们通过标准的日志库建立了一个新的日志框架。这是通过.json文件完成的,并且工作正常。 我具有以下使用.json文件的功能:
6
['https://images-na.ssl-images-amazon.com/images/I/31JLKXyjA5L._SS40_.jpg', 'https://images-na.ssl-images-amazon.com/images/I/51ZZMf1JVfL._SS40_.jpg', 'https://images-na.ssl-images-amazon.com/images/I/416%2BBQU%2BtuL._SS40_.jpg', 'https://images-na.ssl-images-amazon.com/images/I/41CdeeG0HGL._SS40_.jpg', 'https://images-na.ssl-images-amazon.com/images/I/41bZb0qgNPL._SS40_.jpg', 'https://images-na.ssl-images-amazon.com/images/I/219h80ACoQL._SS40_.jpg']
{0: 'https://images-na.ssl-images-amazon.com/images/I/31JLKXyjA5L._SS40_.jpg', 1: 'https://images-na.ssl-images-amazon.com/images/I/51ZZMf1JVfL._SS40_.jpg', 2: 'https://images-na.ssl-images-amazon.com/images/I/416%2BBQU%2BtuL._SS40_.jpg', 3: 'https://images-na.ssl-images-amazon.com/images/I/41CdeeG0HGL._SS40_.jpg', 4: 'https://images-na.ssl-images-amazon.com/images/I/41bZb0qgNPL._SS40_.jpg', 5: 'https://images-na.ssl-images-amazon.com/images/I/219h80ACoQL._SS40_.jpg'}
现在,在我们创建的日志文件中,我还要包含stdout / stderr。 这是因为行为的输出是通过上下文输出到stdout / stderr的。
我创建了一个新的挂钩来设置日志记录:
def custom_logger():
import logging.config
def load_config():
with open('/logging.json', 'r') as logging_config_file:
return json.load(logging_config_file)
cfg = load_config()
logging.config.dictConfig(cfg)
return cfg
但是到目前为止,我无法捕获行为的输出并将其解析到我自己的记录器中。
如何将行为上下文输出重定向到记录器?
这是我控制台中的atm(只有CUSTOM_LOGGER进入文件):
from . import register_hook
def before_all(context):
pass
register_hook(before_all)
但是我希望在日志中看到这样的内容:
Feature: Test
Scenario: dummy scenario
When do nothing
2019-03-25 14:41:23,782 - CUSTOM_LOGGER - INFO - test logging.
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
1 step passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s