Change Flask logs from INFO to DEBUG Change Flask logs from INFO to DEBUG flask flask

Change Flask logs from INFO to DEBUG


I'm not sure about a way to downgrade log level of requests (as it usually is stated explicitly in the code like logging.info("...")) but the following may help you to reduce the verbosity of Flask itself.

Python allows you to have multiple loggers, each with its own log level.You can modify any existing logger if you know the module name it is in or the name it was registered with as described here.

For example:

import logginglogger = logging.getLogger("mypackage.mymodule")  # or __name__ for current modulelogger.setLevel(logging.ERROR)

The above can be done for any python module. Flask provides a logger per app. You can get a reference to it like this:

import loggingfrom flask import Flaskapp = Flask(__name__)  # or instead of __name__ provide the name of the moduleapp.logger.setLevel(logging.ERROR)


In fact, there is a way to downgrade a log record from INFO to DEBUG (even if it was already emitted using a call such as info()). This can be achieved using a filter attached to a logger. According to the docs a filter checks:

Is the specified record to be logged? Returns zero for no, nonzero for yes. If deemed appropriate, the record may be modified in-place by this method.

So a filter may change the level of a log record (levelno and levelname attributes). Later on, a handler may then allow or drop this record based on the new level.


Just in case anyone visits this place,

I'm facing the same issue as well. It seems that print calls have the tendency to 'not run'. But if you use the logger instead of print you will find that codes are actually still running.

Not quite sure what the reason is, but when other sections of my code starts running suddenly all the old prints will appear.

tldr; don't use print, use logger