1

How can I remove all the messages from the console that flask logs.

For a quick note, I tried:

import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app.logger.disabled = True
log.disabled = True

But it only prevents the request logs not the server start.

  • 1
    Does this answer your question? [Disable console messages in Flask server](https://stackoverflow.com/questions/14888799/disable-console-messages-in-flask-server) – sahasrara62 Apr 23 '20 at 14:12
  • If you don't want to see that warning, you could *"Use a production WSGI server instead."* – jonrsharpe Apr 23 '20 at 14:13

2 Answers2

3

Here's a working sample:

from flask import Flask
app = Flask(__name__)

import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app.logger.disabled = True
log.disabled = True

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
Bob
  • 561
  • 5
  • 17
-1

This should work:

import logging    
logging.getLogger('werkzeug').disabled = True

But please do use a production server like uwsgi with something in front of it, like nginx.

masnun
  • 11,635
  • 4
  • 39
  • 50
  • `logging.getLogger('werkzeug').disabled` returns a boolean, it is hard to assign value to `False` – khaz Aug 13 '23 at 05:29