Logging?

Showing 1-8 of 8 messages
Logging? Joseph Turian 9/14/09 7:07 PM
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
Re: Logging? Rolando Espinoza La fuente 9/14/09 7:52 PM

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

Re: Logging? Bret Taylor 9/14/09 7:56 PM
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:
Re: Logging? Joseph Turian 9/14/09 10:43 PM
Thank you for the information, Rolando + Bret.
This definitely belongs in the wiki-like documentation, once you get
that set up.

Best,
   Joseph
Re: Logging? Attila Babo 9/16/09 3:38 PM
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

Re: Logging? Ralf Schmitt 9/16/09 4:48 PM
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 "--"

Re: Logging? Bret Taylor 9/17/09 9:04 AM
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
Re: Logging? ben 9/17/09 9:46 AM