I am running Flask on a Docker container with wsgi. When I look at the Docker container all I see is the wsgi logs, not the Flask logs. I have added the code below and I don’t see the logs anywhere. For development I will need to see the output that get printed to screen and/or any errors that pop up. Not sure how to capture them.
from flask import Flask
import logging
import logging.handlers
# add for logging, remove for production
handler = logging.handlers.SysLogHandler(address='/var/log')
handler.setFormatter(logging.Formatter('flask [%(levelname)s] %(message)s'))
def create_app():
app = Flask(__name__)
#add for logging, remove for production
app.logger.addHandler(handler)
return app
——– uwsgi.ini ——–
[uwsgi]
module = wsgi:app
master = true
processes = 5
buffer-size = 32768
http = 0.0.0.0:5000
req-logger = file:/var/log/uwsgi/cart-req.log
logger = file:/var/log/uwsgi/cart-err.log
chmod-socket = 660
vacuum = true
die-on-term = true
py-autoreload = 1
2
Answers
This is what worked for me. https://improveandrepeat.com/2021/03/python-friday-63-logging-in-flask/
and then added this line to print the logs
current_app.logger.info("Testing Testing")
Depending on your setup you can use the
StreamHandler
withstdout
: