Sometimes, we want to disable console messages in a Python Flask server.
In this article, we’ll look at how to disable console messages in a Python Flask server.
How to disable console messages in a Python Flask server?
To disable console messages in a Python Flask server, we can call setLevel
on the logger object.
For instance, we write
from flask import Flask
app = Flask(__name__)
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
to get the logger with
log = logging.getLogger('werkzeug')
Then we set the logger to only log errors with
log.setLevel(logging.ERROR)
Conclusion
To disable console messages in a Python Flask server, we can call setLevel
on the logger object.