When implementing / starting server using flask in python, the following log may appear. If the log frequency is high, it may lead to an increase in CPU load, and there are times when you want to suppress logging.
127.1.1.0 - - [15/Nov/2020 hh:mm:ss] "GET / HTTP/1.1" 200
127.1.1.0 - - [15/Nov/2020 hh:mm:ss] "GET / HTTP/1.1" 200
127.1.1.0 - - [15/Nov/2020 hh:mm:ss] "GET / HTTP/1.1" 200
127.1.1.0 - - [15/Nov/2020 hh:mm:ss] "GET / HTTP/1.1" 200
Log suppression seems to be good if you output the log to / dev / null as follows
import logging
from flask import Flask
app = Flask(__name__)
# WebAPI
@app.route("/", methods=["GET"])
def root():
return "hello world"
if __name__ == "__main__":
# app run
l = logging.getLogger()
l.addHandler(logging.FileHandler("/dev/null"))
app.run(debug=True, host="0.0.0.0", port=5000)
Prevent flask default log output
Recommended Posts