8

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.

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.