我有最简单的龙卷风应用程序:
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()
Tornado不断向stderr报告错误请求:
WARNING:tornado.access:404 GET / (127.0.0.1) 0.79ms
问题:它希望防止记录错误消息。怎样?
Tornado版本3.1;Python2.6
你也可以简单地(在一行中)做:
前面的答案是正确的,但有点不完整。这将把所有内容发送给NullHandler:
很明显,当我们启动龙卷风时,“有人”正在初始化日志子系统。以下是
ioloop.py
中揭示奥秘的代码:调用
basicConfig
并配置默认的stderr
处理程序。因此,要为tonado访问设置正确的日志记录,您需要:
将处理程序添加到
tornado.access
记录器:logging.getLogger("tornado.access").addHandler(...)
禁用上述记录器的传播:
logging.getLogger("tornado.access").propagate = False
。否则消息将同时到达您的处理程序和stderr
相关问题 更多 >
编程相关推荐