如何为tasks
函数生成render_tasks
参数(在eliottree docs中提及?)
import json, sys
from eliottree import tasks_from_iterable, render_tasks
# Or `codecs.getwriter('utf-8')(sys.stdout).write` on Python 2.
render_tasks(sys.stdout.write, tasks, colorize=True)
我认为应该以某种方式使用tasks_from_iterable
,但它消耗的是什么?
答案 0 :(得分:0)
我已经弄清楚了。相反,to_file
您必须将add_destination
与功能对象一起使用,该功能对象将在以下情况下收到message
Message.log()
被称为:
from sys import stdout
from codecs import getwriter
from eliottree import tasks_from_iterable, render_tasks
from eliot import add_destination
add_destination(render_stdout)
def render_stdout(message):
render_tasks(getwriter('utf-8')(stdout).write, tasks_from_iterable([message]), colorize=True, human_readable=True)
整个树不会在这里渲染,一次只能渲染一个分支,但这就是你生成艾略特任务的方式。