How to log requests to stdout in Tornado web server?

寵の児 提交于 2019-12-04 23:22:36

Add this to your app:

import tornado.options
tornado.options.parse_command_line()

The parse_command_line function sets up logging. You can then pass --logging=loglevel (e.g. debug)

You can add this to you application:

from tornado.log import enable_pretty_logging
enable_pretty_logging()

By default it writes logs to stdout.

Why don't you print? Use print self.request somewhere inside the request handler (maybe inside the prepare method).

Or better:

class BaseHandler(tornado.web.RequestHandler):
    def prepare(self):
        print self.request

class SomeHandler(BaseHandler):
    ...

use a base class for your request handlers and subclass it from that time on.

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