开发者

How to make Twisted use Python logging?

开发者 https://www.devze.com 2022-12-23 14:20 出处:网络
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 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 reacto开发者_如何学运维r to use that instead?

What's the usual pattern for this?


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().


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

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

精彩评论

暂无评论...
验证码 换一张
取 消