Disable Console Messages in Flask Server

Prevent Flask from double logging when running in console

Use

application.app.logger.handlers.clear()

instead of

application.app.logger.handlers.pop()

Cannot disable logging on flask_socketio and eventlet server

Okay, I figured out why I couldn't disable logging. I accidentally had two different deployments running.

When run.bat calls flask run, it started a server on Werkzeug on port 8000, and never runs app.py, which starts a server on Eventlet on port 5000.

All of the code in app.py was correct, it was just starting the eventlet server on a port I wasn't visiting. When I specified the correct port with socketio.run(app, port=8000, log_output=False, debug=False) and changed flask run to py app.py, the server works how I expected, with no logging input.

Disable logging in Flask-Mail when sending message

Figured this one out:

Flask-Mail uses Python's smtplib to send mail. smtplib does not use the logging module, but it prints information for debugging to stderr.

smtplib includes following method:

def set_debuglevel(self, debuglevel):
"""Set the debug output level.

A non-false value results in debug messages for connection and for all
messages sent to and received from the server.

"""
self.debuglevel = debuglevel

If we use Flask-Mail, we can set this variable when we initialize our app like this:

app = Flask(__name__)
mail = Mail(app)
app.extensions['mail'].debug = 0

Any output is now suppressed.



Related Topics



Leave a reply



Submit