如何设置扭曲.py使用IPlugin时使用ILogObserver?

2024-06-02 15:40:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想改道扭曲.py的日志记录到python的日志记录。通常启动.tac文件时,我可以轻松地执行以下操作:

from twisted.python.log import PythonLoggingObserver, ILogObserver
from twisted.application import service

application = service.Application("FooApp")
application.setComponent(ILogObserver, PythonLoggingObserver().emit)

但是,我在写IPlugin时似乎没有Application。相反,我只有一个实现IServiceMakerIPlugin的类,其中makeService返回service.Service。如何设置日志观察者?在

请注意,我不只是想添加一个python日志观察者,而是希望重定向twistd的日志记录,以便它只通过python的内置日志系统。在


Tags: 文件frompyimportlogapplicationservice记录
1条回答
网友
1楼 · 发布于 2024-06-02 15:40:17

看看twistd的 logger参数:

# mylogger.py
from twisted.python import log

def logger():
    return log.PythonLoggingObserver().emit

然后调用twistd:twistd logger=mylogger.logger。在

相关问题 更多 >