Prevent Flask from double logging when running in console
Use
application.app.logger.handlers.clear()
instead ofapplication.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
Python Ignore Certificate Validation Urllib2
Pandas - Add New Column to Dataframe from Dictionary
How to Crop the Internal Area of a Contour
Python MySQL Connector - Unread Result Found When Using Fetchone
Getting Data from Ctypes Array into Numpy
What Are All the Dtypes That Pandas Recognizes
How to Import a Module in Python with Importlib.Import_Module
Python Element-Wise Tuple Operations Like Sum
Python Progress Bar and Downloads
Plotting Results of Hierarchical Clustering Ontop of a Matrix of Data in Python
Why Isn't Assigning to an Empty List (E.G. [] = "") an Error
How Does Sklearn.Svm.Svc's Function Predict_Proba() Work Internally
Python Wildcard Search in String