Categories
Python Answers

How to disable console messages in a Python Flask server?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *