How to log HTTP response in Tornado?

怎甘沉沦 提交于 2019-12-11 00:58:43

问题


I want to be able to log HTTP request and response in tornado. This seems to be easy to do with request:

def log_function(handler):
    info = {
        'Method' : handler.request.method,
        'Host' : handler.request.host,
        'URL' : handler.request.uri
     }

How can the same thing be achieved for response? The response status_code can be retrieved by calling

handler.get_status()

How do I get a body of a response?


回答1:


Tornado doesn't save the response; it sends it directly to the client. If you want to log the response you'll have to save it yourself. You can either do this in your handler code or override the write() and finish() methods to intercept it as it is being written.



来源:https://stackoverflow.com/questions/42562718/how-to-log-http-response-in-tornado

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!