I'm getting the following error with Tornado:
No handlers could be found for logger "tornado.application"
I've read through the docs, and it appears that I need to define this:
access_log = logging.getLogger("tornado.access")
app_log = logging.getLogger("tornado.application")
gen_log = logging.getLogger("tornado.general")
but then what? What do I do with these things? The error isn't going away.
also note that this is the first line of my main() function:
tornado.options.parse_command_line()
I've also explicitly added this:
logging.basicConfig()
Could someone please point me to a clear/explicit example of how to use logging in tornado.
Also, I've noticed that all my 200 level requests are being routed to stderr, instead of stdout, how do I redirect that to stdout. I only want the 500-level errors to go to stderr.
Don't mind :
access_log = logging.getLogger("tornado.access")
app_log = logging.getLogger("tornado.application")
gen_log = logging.getLogger("tornado.general")
Those are directly subtracted from Tornado's source code for you to see them in the documentation. You don't need to put them anywhere as they are already baked into tornado. The only thing you need to do is to configure the logger.
If you go to : http://docs.python-guide.org/en/latest/writing/logging/ you'll find a way to load the config. There are three parts you need to put in your code:
1) Import dependencies:
import logging
from logging.config import dictConfig
2) Put the config in a dictionary (if you want to have a cleaner code you might want to import from a file but leave that for later):
logging_config = dict(
version = 1,
formatters = {
'f': {'format':
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s'}
},
handlers = {
'h': {'class': 'logging.StreamHandler',
'formatter': 'f',
'level': logging.DEBUG}
},
loggers = {
'tornado.general': {'handlers': ['h'],
'level': logging.DEBUG}
}
)
** I literally changed only one line from the example in python's documentation to handle tornado.general
3) Load the config:
dictConfig(logging_config)
This will solve your first problem which is having your application returning: No handlers could be found for logger "tornado.application"
If you want a more advanced example for a config file that outputs to files check this out: https://gist.github.com/blalab/d8ccd9c83f025197fac8c2a2d680c58e
Regarding your question regarding stdout , stderror you should post it in SO as a different question