Logging?

4,161 views
Skip to first unread message

Joseph Turian

unread,
Sep 14, 2009, 10:07:48 PM9/14/09
to Tornado Web Server
What is the simplest way to log messages to stderr or stdout?

I tried print, as well as the python logging module, but I don't see
the messages show up anywhere.

Thanks,
Joseph

Rolando Espinoza La Fuente

unread,
Sep 14, 2009, 10:52:14 PM9/14/09
to python-...@googlegroups.com

Hi, i had this problem too and discovered that need to run parse_command_line()
to setup logging by default. Check the code in tornado.options:
http://github.com/facebook/tornado/blob/master/tornado/options.py#L126

Here is an example:

def main():
application = tornado.web.Application([
(r"/", MainHandler),
])

# this line will setup default logging no matter if you use command options
tornado.options.parse_command_line()
logging.info("starting torando web server")

http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888) # hardcoded port
tornado.ioloop.IOLoop.instance().start()


Regards,

--
ø Rolando Espinoza La fuente

Bret Taylor

unread,
Sep 14, 2009, 10:56:15 PM9/14/09
to Tornado Web Server
Tornado uses the Python logging facility by default. As Rolando
mentioned, we turn on "pretty printing" for log messages when you use
the Tornado options module, but you don't actually have to. If you
just ran logging.getLogger().setLevel(logging.INFO) at the beginning
of your program and then used logging.info("...") for messages, you
would see them print to stdout. Our options module color codes the
output and does a few other useful things for interactive debugging.

If you use the Tornado options module, you can set the log level with
--logging=info / --logging=debug / --logging=warning, etc.

Bret

On Sep 14, 7:52 pm, Rolando Espinoza La Fuente <dark...@gmail.com>
wrote:

Joseph Turian

unread,
Sep 15, 2009, 1:43:27 AM9/15/09
to Tornado Web Server
Thank you for the information, Rolando + Bret.
This definitely belongs in the wiki-like documentation, once you get
that set up.

Best,
Joseph

Attila Babo

unread,
Sep 16, 2009, 6:38:25 PM9/16/09
to python-...@googlegroups.com
Let me suggest to separate logging setup and
tornado.options.parse_command_line(). Logging to a file is a common
need, I've tried to use a command line option to specify a logfile and
set up my own logging but failed utterly because of the unwanted side
effect of parse_command_line.

Attila

Ralf Schmitt

unread,
Sep 16, 2009, 7:48:17 PM9/16/09
to python-...@googlegroups.com
On Tue, Sep 15, 2009 at 4:52 AM, Rolando Espinoza La Fuente
<dar...@gmail.com> wrote:
>
> Hi, i had this problem too and discovered that need to run parse_command_line()
> to setup logging by default. Check the code in tornado.options:
> http://github.com/facebook/tornado/blob/master/tornado/options.py#L126
>

If someone wonders why they do not get log output, it could be cause
they pass non-option arguments to their programs.
see http://github.com/schmir/tornado/commit/f4590b4ddb93e37f3d207f6070650a3141b14ec1
for a fix. it also fixes handling of "--"

Bret Taylor

unread,
Sep 17, 2009, 12:04:47 PM9/17/09
to Tornado Web Server
We don't have any special logging facilities in Tornado - we use
Python's built-in logging module: http://docs.python.org/library/logging.html.
It in no way depends on our options module. The only thing our options
module does is introduce the ability to change the log level through
command line options (--logging=warning, etc), and it color codes the
log output in an interactive console.

We will update the docs to explain logging, but I wanted to make sure
it is clear that Tornado logging is not anything special nor is it
dependent on any Tornado module.

Bret

Ben Eliott

unread,
Sep 17, 2009, 12:46:43 PM9/17/09
to python-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages