IPython.parallel - 我可以将自己的日志写入引擎日志吗? [英] IPython.parallel - can I write my own log into the engine logs?

查看:189
本文介绍了IPython.parallel - 我可以将自己的日志写入引擎日志吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在相关的引擎日志中记录我传递给引擎的函数的输出。

I'd like to be able to log outputs from the functions I pass to my engines in the relevant engine logs.

即:

data = /* my list of data to operate on */
def fn(inval):
    import logging
    log = logging.getLogger()
    log.error('This is on the engine')
    // do stuff
    return result

calculated_data = []
for datum in data:
    calc = view.apply(fn, datum)
    calculated_data.append(calc)

我希望能够在相关的引擎日志中看到针对特定任务运行的日志语句。

I'd like to be able to see the log statements in the relevant engine log that operated on the specific task.

推荐答案

您可以使用以下方式获取当前应用程序的记录器(即本例中的引擎):

You can grab the logger of the current app (i.e. the engine in this case) with:

from IPython.config import Application
log = Application.instance().log

然后正常登录,它将转到引擎日志。

Then log as normal, and it will go to the engine logs.

这篇关于IPython.parallel - 我可以将自己的日志写入引擎日志吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆