Python 如何为eliottree渲染任务生成eliot任务?
如何为Python 如何为eliottree渲染任务生成eliot任务?,python,logging,Python,Logging,如何为render\u tasks函数生成tasks参数(在中提到过?) 我想应该以某种方式使用iterable中的任务,但是iterable消耗了什么呢?我已经弄明白了。取而代之的是到_文件您必须使用添加_目的地函数对象,该函数对象将在调用例如message.log()时接收消息: from sys import stdout from codecs import getwriter from eliottree import tasks_from_iterable, render_tasks
render\u tasks
函数生成tasks
参数(在中提到过?)
我想应该以某种方式使用iterable中的任务,但是iterable消耗了什么呢?我已经弄明白了。取而代之的是
到_文件
您必须使用添加_目的地
函数对象,该函数对象将在调用例如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)
这里不渲染整个树,一次只渲染一个分支,但这就是生成eliot任务的方式
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)