Reputation: 2097
I have a Flask application running inside a container, where I have setup the logging with the StreamHandler()
, so the logs are sent to stdout.
When my uwsgi.ini
file includes a statement to redirect the logs to a file (by using logto
), then the logs from the application are available in the log file intermixed with the uWSGI logs (as it is expected).
But when I remove the logto
from the uwsgi.ini
- because I want those logs sent to the Docker container stdout only the uWSGI logs are visible in the docker container logs, the application logs are not. (the uWSGI logs were there even before)
uwsgi.ini:
[uwsgi]
base = /app_home/app
wsgi-file = /app_home/app/wsgi.py
callable = app
socket = /tmp/uwsgi.sock
chmod-socket = 666
# Log directory - we needed this to be turned off, so the logs are sent to STDOUT
# logto = /var/log/uwsgi/app.log
vacuum = true
master = true
processes = 3
enable-threads = true
uid = app
gid = app
master-fifo = /tmp/fifo0
master-fifo = /tmp/fifo1
chdir = /app_home/app
When the logto
is enabled, then the log file includes the app's logs (as it should):
[2019-03-05 17:19:05,415] INFO in __init__: Initial starting of app...
2019-03-05 17:19:05,415 (9) - INFO - Initial starting of app...- [in ./app/__init__.py:128, function:create_app]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1ad49b0 pid: 9 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 9)
spawned uWSGI worker 1 (pid: 32, cores: 1)
Once the logto
is disabled, then no log file (as expected), but no app logs in the Docker container log either. The docker container looks exactly the same as before:
2019-03-05T22:19:09.956784133Z 2019-03-05 17:19:09,956 CRIT Supervisor running as root (no user in config file)
2019-03-05T22:19:09.959701644Z 2019-03-05 17:19:09,959 INFO supervisord started with pid 1
2019-03-05T22:19:10.961366502Z 2019-03-05 17:19:10,961 INFO spawned: 'nginx' with pid 9
2019-03-05T22:19:10.963312945Z 2019-03-05 17:19:10,962 INFO spawned: 'uwsgi' with pid 10
2019-03-05T22:19:12.928470278Z 2019-03-05 17:19:12,928 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2019-03-05T22:19:12.928498809Z 2019-03-05 17:19:12,928 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
uWSGI documentation shows that the logs are sent to stdout/stderr by default (see https://uwsgi-docs.readthedocs.io/en/latest/Logging.html), so I don't really see a reason why the app's logs would be not sent to stdout with the uWSGI's own logs, but sent to a file with logto
.
Upvotes: 16
Views: 3765
Reputation: 31670
There are two issues:
As uWSGI is running in the Docker container with Supervisor, you need to make supervisor redirect the stdout of uwsgi to its stdout.
supervisord.conf
:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
While this has worked with other applications (like nginx), it was not enough for uWSGI, see step #2:
A special flag (--log-master
) needs to be added to uWSGI to delegate the logging to the master process:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
And then, the logs from the Flask applications are visible in the Docker container log.
This answer was posted as an edit to the question UWSGI does not redirect application stdout to stdout, only to file by the OP Zoltan Fedor under CC BY-SA 4.0.
Upvotes: 1