我尝试用twisted写一个小服务。
我创建了一个简单的应用程序,并尝试向我的服务添加 2 个 ILogObserver。但不幸的是,它不起作用。最后添加的观察者始终是将要使用的观察者。
def log(eventDict):
...
def mylog(eventDict):
...
LoopingCall(logSomething).start(1)
application = Application("twistd-logging")
application.setComponent(ILogObserver, log)
application.setComponent(ILogObserver, mylog)
预先感谢您的帮助。
我找到了解决方案。我只需要添加:
from twisted.python.log import addObserver
如果我有辅助日志观察者
def mylogobserver(eventDict):
# doSth
我可以简单地添加它
addObserver(mylogobserver)