Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable console messages in Flask server

Tags:

python

flask

I have a Flask server running in standalone mode (using app.run()). But, I don't want any messages in the console, like

127.0.0.1 - - [15/Feb/2013 10:52:22] "GET /index.html HTTP/1.1" 200 - ... 

How do I disable verbose mode?

like image 934
ATOzTOA Avatar asked Feb 15 '13 05:02

ATOzTOA


2 Answers

You can set level of the Werkzeug logger to ERROR, in that case only errors are logged:

import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) 

Here is a fully working example tested on OSX, Python 2.7.5, Flask 0.10.0:

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() 
like image 170
Drewes Avatar answered Oct 01 '22 07:10

Drewes


This solution provides you a way to get your own prints and stack traces but without information level logs from flask suck as 127.0.0.1 - - [15/Feb/2013 10:52:22] "GET /index.html HTTP/1.1" 200

from flask import Flask import logging  app = Flask(__name__) log = logging.getLogger('werkzeug') log.disabled = True 
like image 21
iamtodor Avatar answered Oct 01 '22 06:10

iamtodor