我想将twistd.py的日志重定向到python的日志记录。在正常启动.tac文件时,我可以轻松地这样做:
from twisted.python.log import PythonLoggingObserver, ILogObserver
from twisted.application import service
application = service.Application("FooApp")
application.setComponent(ILogObserver, PythonLoggingObserver().emit)但是,在编写Application时,我似乎没有IPlugin。相反,我只有一个实现IServiceMaker和IPlugin的类,其中makeService返回一个service.Service。如何设置日志观察者?
请注意,我不只是想添加python日志记录观察者,我希望重定向twistd的日志记录,以便它只通过python的内置日志系统。
发布于 2013-03-05 17:16:54
看看twistd的--logger参数:
# mylogger.py
from twisted.python import log
def logger():
return log.PythonLoggingObserver().emit然后调用twistd:twistd --logger=mylogger.logger。
https://stackoverflow.com/questions/15229252
复制相似问题