How to make Twisted use Python logging?

牧云@^-^@ 提交于 2019-12-03 18:35:50

问题


I've got a project where I'm using Twisted for my web server. When exceptions occur (such as network errors), it's printing to the console.

I've already got logging through Python's built-in log module - is there any way to tell the reactor to use that instead?

What's the usual pattern for this?


回答1:


Found it. It's actually quite easy:

from twisted.python import log
observer = log.PythonLoggingObserver(loggerName='logname')
observer.start()

You just set loggerName to the same logger name that you're using in logging.getLogger().




回答2:


You can use twisted.python.log. For example:

from twisted.python import log
log.msg('Hello, world.')


来源:https://stackoverflow.com/questions/2493644/how-to-make-twisted-use-python-logging

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!