我有极简的“旋风”应用:
import tornado.ioloop
import tornado.web
class PingHandler(tornado.web.RequestHandler):
def get(self):
self.write("pong\n")
if __name__ == "__main__":
application = tornado.web.Application([ ("/ping", PingHandler), ])
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()龙卷风不断向stderr报告错误请求:
WARNING:tornado.access:404 GET / (127.0.0.1) 0.79ms问题:希望防止它记录错误消息。多么?
龙卷风版本3.1;Python2.6
发布于 2014-01-20 13:15:05
很明显,“某人”是初始化日志子系统时,我们启动龙卷风。下面是来自ioloop.py的代码,它揭示了其中的奥秘:
def start(self):
if not logging.getLogger().handlers:
# The IOLoop catches and logs exceptions, so it's
# important that log output be visible. However, python's
# default behavior for non-root loggers (prior to python
# 3.2) is to print an unhelpful "no handlers could be
# found" message rather than the actual log entry, so we
# must explicitly configure logging if we've made it this
# far without anything.
logging.basicConfig()basicConfig被调用并配置默认的stderr处理程序。
因此,要为tonado访问设置适当的日志记录,您需要:
tornado.access记录器添加一个处理程序:logging.getLogger("tornado.access").addHandler(...)logging.getLogger("tornado.access").propagate = False。否则,消息将同时到达处理程序和stderr。发布于 2015-07-01 21:56:05
先前的答案是正确的,但有点不完整。这将向NullHandler发送所有内容:
hn = logging.NullHandler()
hn.setLevel(logging.DEBUG)
logging.getLogger("tornado.access").addHandler(hn)
logging.getLogger("tornado.access").propagate = False发布于 2015-09-07 11:49:11
您也可以非常简单地(在一行中)做:
logging.getLogger('tornado.access').disabled = Truehttps://stackoverflow.com/questions/21234772
复制相似问题