Twisted:如何静默某些日志消息?
我的应用程序中有 XML-RPC 方法,可以生成大量像这样的 Twisted 日志消息,这些消息又通过 Python 的 logging
模块进行记录:
2011-09-08 18:00:51.399553 UTC 信息 XXX.XXX.XXX.XXX - - [2011 年 9 月 8 日:18:00:50 +0000] “POST /RPC2 HTTP/1.0" 200 129 "-" "xmlrpclib.py/1.0.1 (by www.pythonware.com)"
这些日志消息对我来说不是必需的,我想将它们更改为级别 logging.DEBUG
或完全抑制它们。支持吗?
编辑:这些是服务器端日志消息,当我调用 twisted.web.xmlrpc.XMLRPC
对象的方法时被记录。这些对象在 twisted.web.server.Site
和 twisted.web.vhost.NameVirtualHost
对象下的层次结构中使用(如 putChild
) ,并且我使用默认的 SelectReactor
。我想这些类或请求对象中的任何一个都可能是实际记录这些的类或请求对象。
I have XML-RPC methods in my application that generate a lot of Twisted log messages like this, which are in turn logged through Python's logging
module:
2011-09-08 18:00:51.399553 UTC INFO XXX.XXX.XXX.XXX - - [08/Sep/2011:18:00:50 +0000] "POST /RPC2 HTTP/1.0" 200 129 "-" "xmlrpclib.py/1.0.1 (by www.pythonware.com)"
These log messages are not necessary for me and I would like to either change them to level logging.DEBUG
or suppress them entirely. Is this supported?
EDIT: These are server-side log messages, being logged when I call methods of twisted.web.xmlrpc.XMLRPC
objects. These objects are used in a hierarchy (as in putChild
) underneath twisted.web.server.Site
and twisted.web.vhost.NameVirtualHost
objects, and I'm using the default SelectReactor
. I suppose any of these classes or the request object could be the one actually logging these.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
twisted.web.xmlrpc.Proxy
使用工厂来设置其 HTTP 连接(以通常的方式)。 Twisted 工厂的noisy
属性控制是否记录启动和停止消息。您可以像这样更改 Proxy 工厂的noisy
属性:与当
noisy
设置为时程序的输出进行比较确实如此。
对于 XML-RPC 服务器,日志消息来自托管 XML-RPC 资源的
twisted.web.server.Site
。Site
初始值设定项接受logPath
参数;如果您传入此参数的路径,则请求日志将写入该路径而不是主日志。您还可以重写发出这些日志消息的Site.log
方法,以仅忽略您想要忽略的消息,或者不执行任何操作以完全禁用请求日志。twisted.web.xmlrpc.Proxy
uses a factory to set up its HTTP connection (in the usual way). Thenoisy
attribute of the factories Twisted provides controls whether they log start and stop messages. You can change thenoisy
attribute ofProxy
's factory like this:Compare to the output of the program when
noisy
is set toTrue
.For an XML-RPC server, the log messages come from the
twisted.web.server.Site
hosting the XML-RPC resource. TheSite
initializer accepts alogPath
argument; if you pass in a path for this parameter, then the request logs will be written to that path instead of to the main log. You can also override theSite.log
method which is what emits these log messages, to either omit just the ones you want to omit, or to do nothing to disable the request log entirely.