Suppress python3 flask logging

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)

reference

Prevent flask default log output

Recommended Posts

Suppress python3 flask logging
Python Logging
Logging properly in Python
I implemented Python Logging
Programming with Python Flask
Python --Quick start of logging
Install Python and Flask (Windows 10)
Web application with Python + Flask ② ③
Web application with Python + Flask ④
SNS Python basics made with Flask
Python
Next, use Python (Flask) for Heroku!
flask
Python logging and dump to json
[Python] Read the Flask source code
Application development with Docker + Python + Flask
Try logging in to qiita with Python
Install Python and Flask (Windows 10)
flask
flask
First Flask
POST variously with Python and receive with Flask
[Python] Run Flask on Google App Engine
Page cache in Python + Flask with Flask-Caching
Favicon placement (when using Python, Flask, Heroku)
Coexistence of Flask logging and other module logging
Let's observe the Python Logging cookbook SocketHandler
Easy web app with Python + Flask + Heroku
[Python] Quickly create an API with Flask
Image sending / receiving memo in Python (Flask)
Get Cloud Logging available in Python in 10 minutes