13165

Question:
My flask application uses a module which gets a logger like this:
import logging
logger = logging.getLogger("XYZ")
...
logger.debug("stuff")
Without having to modify anything in the module, can I configure flask such that the module will get flask's app.logger when it makes the getLogger("XYZ") call?
Answer1:Yes, you can configure it.
By default flask logger's name is your app name, but flask has setting <a href="http://flask.pocoo.org/docs/config/#builtin-configuration-values" rel="nofollow">LOGGER_NAME</a>.
Answer2:<a href="https://stackoverflow.com/a/18379764/747872" rel="nofollow">This</a> solution worked to me:
import logging
logger = logging.getLogger('werkzeug')
logger.debug('stuff')
The default Flask configuration seems to use the logger name werkzeug
. Adding or changing handlers for this logger changes the way Flask logs.
PS.: Python 3.5, Flask 0.12.2