如何让 Twisted 使用 Python 日志记录? [英] How to make Twisted use Python logging?

查看:44
本文介绍了如何让 Twisted 使用 Python 日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我将 Twisted 用于我的 Web 服务器.当发生异常(例如网络错误)时,它会打印到控制台.

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.

我已经通过 Python 的内置日志模块进行了日志记录 - 有什么方法可以告诉反应器使用它来代替吗?

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

通常的模式是什么?

推荐答案

找到了.其实很简单:

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

您只需将 loggerName 设置为您在 logging.getLogger() 中使用的相同记录器名称.

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

这篇关于如何让 Twisted 使用 Python 日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆