tornado logging

3,003 views
Skip to first unread message

aliane abdelouahab

unread,
Apr 27, 2013, 12:19:26 PM4/27/13
to Tornado Web Server
hi
i'm a newbie in internet technology and i discover things everyday,
and today i discovered the Logging concept, in the past i saw the word
but ignored it, until i found this:
https://code.google.com/p/logstalgia/
and when i tried to run it, it asked for a log file, and when i
searched how to make log files, found that tornado will use python
standard''s logging module, can you please provide me the version of
hello word using the logging module?
and then, i found a related thread that coined mongodb in logging, and
sent me here:
https://github.com/puentesarrin/mongodb-log
how to use it with tornado? or can i simply use motor to catch the log
and save it asynchronously?

A. Jesse Jiryu Davis

unread,
Apr 27, 2013, 12:55:27 PM4/27/13
to python-...@googlegroups.com
Try this:

import logging

import tornado.ioloop
import tornado.web
import tornado.options

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

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

if __name__ == "__main__":
    tornado.options.parse_command_line()
    logging.info('Starting up')
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

Adding parse_command_line() makes Tornado configure logging. On the command line, if you do "python script.py --help" you'll see various options related to logging. If you do "python script.py" you'll see it log "Starting up" to the terminal window. You can do "python script.py --log_file_prefix=log" and Tornado will make a logfile. Start the script and observe that a file named "log" is created, open it and see that "Starting up" was written to it.



--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



aliane abdelouahab

unread,
Apr 27, 2013, 1:16:28 PM4/27/13
to Tornado Web Server
ah! thank you!
and what about storing it to mongodb? i think i must override
something to send the stdout to mongodb insteand of the console?

On 27 avr, 17:55, "A. Jesse Jiryu Davis" <je...@emptysquare.net>
wrote:

A. Jesse Jiryu Davis

unread,
Apr 27, 2013, 1:37:19 PM4/27/13
to python-...@googlegroups.com
I wouldn't actually recommend storing log messages in MongoDB. The interface for logging is synchronous, so it's best not to do network I/O in logging from Tornado. I'd prefer to just write messages to a file.

If you want to do some work you could use PyMongo to log, and insert messages into MongoDB using w=0 to avoid blocking. I don't have a handy example of that.

aliane abdelouahab

unread,
Apr 27, 2013, 3:08:35 PM4/27/13
to Tornado Web Server
ah, now i get it, thank you for clarifications :)

On 27 avr, 18:37, "A. Jesse Jiryu Davis" <je...@emptysquare.net>
wrote:
> I wouldn't actually recommend storing log messages in MongoDB. The
> interface for logging is synchronous, so it's best not to do network I/O in
> logging from Tornado. I'd prefer to just write messages to a file.
>
> If you want to do some work you could use PyMongo to log, and insert
> messages into MongoDB using w=0 to avoid blocking. I don't have a handy
> example of that.
>
> On Sat, Apr 27, 2013 at 1:16 PM, aliane abdelouahab <alabdeloua...@gmail.com

Jorge Puente Sarrín

unread,
Apr 27, 2013, 3:14:31 PM4/27/13
to python-...@googlegroups.com
Hi Aliane, Hi Jesse,

I have written a snippet with the recommendation by Jesse using mongolog.


--
Jorge Puente Sarrín.

A. Jesse Jiryu Davis

unread,
Apr 27, 2013, 3:16:17 PM4/27/13
to python-...@googlegroups.com
Cool, nice work.

aliane abdelouahab

unread,
Apr 27, 2013, 3:36:06 PM4/27/13
to Tornado Web Server
wow! thank you! it is a jewel, thank you :)
> > For more options, visithttps://groups.google.com/groups/opt_out.
>
> --
> Jorge Puente Sarrín.
Reply all
Reply to author
Forward
0 new messages