pythonloggingflask-socketioeventlet

Cannot disable logging on flask_socketio and eventlet server


I have a flask_socketio app with eventlet that runs on Windows, but I can't figure out how to disable the large amounts of log messages. So far I've looked at Disabling logger in flask-socketio and SocketIO server refuses to shutdown with Ctrl+C, but neither has helped provide more information. I'm wondering if I did not set the app up correctly now. I know it's not good practice to have my routes and socketio events together, but I don't think that should impact the server.

Here's the instantiation code (where create_app is simply app = Flask(__name__, template_folder="templates")):

from flask_socketio import SocketIO, send, join_room, leave_room
from flask import Flask, render_template
from application import create_app

import logging


app = create_app()
socketio = SocketIO(app)

@app.route('/')
def index():
    return render_template('index.html')

@socketio.on('join')

...

if __name__ == '__main__':
    logging.getLogger('socketio').setLevel(logging.ERROR)
    logging.getLogger('engineio').setLevel(logging.ERROR)
    logging.getLogger('eventlet').setLevel(logging.ERROR)
    logging.getLogger('eventletwebsocket.handler').setLevel(logging.ERROR)
    socketio.run(app, log=False)

Here's my startup script, run.bat:

set FLASK_APP=app.py
set FLASK_ENV=production
start "" http://localhost:8000/
flask run --port=8000
cmd /k

And here's the console output on startup:

 * Serving Flask app 'app.py' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:8000 (Press CTRL+C to quit)
127.0.0.1 - - [27/Jun/2022 09:42:20] "GET / HTTP/1.1" 200 -
The WebSocket transport is not available, you must install a WebSocket server that is compatible with your async mode to enable it. See the documentation for details. (further occurrences of this error will be logged with level INFO)
127.0.0.1 - - [27/Jun/2022 09:42:20] "GET /socket.io/?EIO=4&transport=polling&t=O6c2kBU HTTP/1.1" 200 -
127.0.0.1 - - [27/Jun/2022 09:42:20] "POST /socket.io/?EIO=4&transport=polling&t=O6c2kC6&sid=ojMZJF2Em0MfSfMMAAAA HTTP/1.1" 200 -
127.0.0.1 - - [27/Jun/2022 09:42:20] "GET /socket.io/?EIO=4&transport=polling&t=O6c2kC6.0&sid=ojMZJF2Em0MfSfMMAAAA HTTP/1.1" 200 -
Message: User has connected
127.0.0.1 - - [27/Jun/2022 09:42:20] "POST /socket.io/?EIO=4&transport=polling&t=O6c2kH2&sid=ojMZJF2Em0MfSfMMAAAA HTTP/1.1" 200 -
127.0.0.1 - - [27/Jun/2022 09:42:20] "GET /socket.io/?EIO=4&transport=polling&t=O6c2kH3&sid=ojMZJF2Em0MfSfMMAAAA HTTP/1.1" 200 -

And of course more 200 requests appear every few seconds. It tells me that WebSocket transport is not available, which is supposed to mean I don't have eventlet installed. This makes me think that it might be running on werkzeug. But pip says that eventlet is installed, and socketio.run(app) should automatically use eventlet if it is installed, right?

Anyways, it's really difficult to debug with so many messages all the time. Could someone help me fix the logging output? Here's what [logging.getLogger(name) for name in logging.root.manager.loggerDict] returns

<Logger urllib3.util.retry (ERROR)>
 <Logger urllib3.util (ERROR)>
 <Logger urllib3 (ERROR)>
 <Logger urllib3.connection (ERROR)>
 <Logger urllib3.response (ERROR)>
 <Logger urllib3.connectionpool (ERROR)>
 <Logger urllib3.poolmanager (ERROR)>
 <Logger charset_normalizer (ERROR)>
 <Logger requests (ERROR)>
 <Logger engineio.client (ERROR)>
 <Logger engineio (ERROR)>
 <Logger engineio.server (ERROR)>
 <Logger concurrent.futures (ERROR)>
 <Logger concurrent (ERROR)>
 <Logger asyncio (ERROR)>
 <Logger tornado.access (ERROR)>
 <Logger tornado (ERROR)>
 <Logger tornado.application (ERROR)>
 <Logger tornado.general (ERROR)>
 <Logger socketio.client (ERROR)>
 <Logger socketio (ERROR)>
 <Logger pkg_resources.extern.packaging.tags (ERROR)>
 <Logger pkg_resources.extern.packaging (ERROR)>
 <Logger pkg_resources.extern (ERROR)>
 <Logger pkg_resources (ERROR)>
 <Logger setuptools.extern.packaging.tags (ERROR)>
 <Logger setuptools.extern.packaging (ERROR)>
 <Logger setuptools.extern (ERROR)>
 <Logger setuptools (ERROR)>
 <Logger setuptools.config._apply_pyprojecttoml (ERROR)>
 <Logger setuptools.config (ERROR)>
 <Logger setuptools.config.pyprojecttoml (ERROR)>
 <Logger socketio.server (ERROR)>

They are all set to ERROR or below! So why so much output still?


Solution

  • 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.