How to log requests to stdout in Tornado web serve

2019-04-18 23:09发布

I'm starting to develop a simple Tornado application, and I'd like to see request log in stdout while I develop. Currently I only see 404 warning messages.

Is there a way to have all requests printed in stdout?

标签: tornado
3条回答
贪生不怕死
2楼-- · 2019-04-18 23:18

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.

查看更多
贪生不怕死
3楼-- · 2019-04-18 23:26

You can add this to you application:

from tornado.log import enable_pretty_logging
enable_pretty_logging()

By default it writes logs to stdout.

查看更多
干净又极端
4楼-- · 2019-04-18 23:27

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)

查看更多
登录 后发表回答