The trouble with Flask logging (i.e., app.logger.info(...), etc.) is that sub modules don't use it, so it seems to me that the only way to globally configure the app's logging is via the underlying python logging mechanism: e.g.,
logging.config.fileConfig('config/logging.conf')
But this doesn't configure Flask's default handlers, so for example, the HTTP logging is not configured. So I get mixed logs:
2015-07-28 14:57:47,320 [main.py][INFO] Starting... # Python log
[2015-07-28 14:58:49] "GET /demo HTTP/1.1" 200 956 0.318825 # Flask log
Can anyone suggest the standard practice for globally configuring logging via a configuration file (i.e., so that I can easily configure individual packages).
ALSO, I cant seem to remove the HTTP logging (GET, etc.) to stderr (which I presume come from werkzeug); setting logging.getLogger('werkzeug').setLevel() only affects the werkzeug logs that are not related to HTTP logging.
Thanks.
I'm pretty sure there is a piece about this in the Flask docs: https://flask.palletsprojects.com/en/1.1.x/logging/#other-libraries
It basically suggests to add the handlers of other libraries to the root of Flask. This is the example they give:
from flask.logging import default_handler
root = logging.getLogger()
root.addHandler(default_handler)
root.addHandler(mail_handler)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With