Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

513
Visualizações
UWSGI does not redirect application stdout to stdout, only to file

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.

EDIT (SOLVED):
So it turns out there were two issues:

  1. As uWSGI is running in the Docker container with Supervisor, I need to make supervisor to 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:

  1. A special flag (--log-master) had 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 whoala, the logs from the Flask applications are visible in the Docker container log.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda