简体   繁体   English

Python Cherrypy:禁用请求记录

[英]Python Cherrypy: Disable logging of requests

I'm trying to silence the logging of http requests from CherryPy. 我正试图使来自CherryPy的http请求的记录无声。 I've tried 我试过了

cherrypy.log.access_file = None

which as I understand it should remove the handler for access logging, but I can't seem to get it to work. 根据我的理解,它应该删除访问日志记录的处理程序,但我似乎无法让它工作。

Apparently, telling CherryPy to stop logging doesn't actually do anything when you've independently configured Python's logging module. 显然,当你独立配置Python的logging模块时,告诉CherryPy停止记录实际上并没有做任何事情。 The solution is to do this: 解决方案是这样做:

cherrypy.log.error_log.propagate = False
cherrypy.log.access_log.propagate = False

(Hat tip to this blog post , which is unfortunately now down.) (帽子提示这个博客文章 ,不幸的是现在已经失败了。)

This is how I normally do: 这就是我通常做的事情:

    access_log = cherrypy.log.access_log
    for handler in tuple(access_log.handlers):
        access_log.removeHandler(handler)

It says on the docs page for the latest version of CherryPy to set the handler to "" not to None 它在文档页面上说明最新版本的CherryPy将处理程序设置为""而不是"" None

# Remove the default FileHandlers if present.
log.error_file = ""
log.access_file = ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM