2

I have a python flask app that I have configured to run via Supevisord. The supervisor.conf file looks something like this -

[inet_http_server]
port=127.0.0.1:9001     

[supervisord]
logfile=/path/to/log/supervisord.log  
logfile_maxbytes=0                          ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=0                           ; # of main logfile backups; 0 means none, default 10
loglevel=debug                              ; log level; default info; others: debug,warn,trace
pidfile=/path/to/supervisord.pid 
nodaemon=false                              ; start in foreground if true; default false
directory=/path/to/project

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=http://127.0.0.1:9001   
history_file=/path/to/.sc_history  ; use readline history if available

[program:my_server]
command=<command to run the program>
directory=/path/to/project
stdout_logfile=/path/to/log/%(program_name)s_stdout.log       ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=0  ; 
stderr_logfile=/path/to/log/%(program_name)s_stderr.log       ; stderr log path, NONE for none; default AUTO
stderr_logfile_backups=0     ; # of stderr logfile backups (0 means none, default 10)

The issue is, when I run the app via supervisord, it logs all outputs - info, debug, error, etc to the %(program_name)s_stderr.log log file and not the %(program_name)s_stdout.log file.

I log my info messages using the python's default logging library as -

logger.info("Some info msg")

What could be the reason for this behaviour?

emotionull
  • 595
  • 2
  • 8
  • 24
  • add redirect_stderr=true. Find more document in the link http://supervisord.org/subprocess.html. – Shivendra Pratap Kushwaha Feb 03 '20 at 12:22
  • Flask simply logs to stderr by default. You can find the details about this here: https://flask.palletsprojects.com/en/1.1.x/logging/ – blues Feb 03 '20 at 14:02
  • Does this answer your question? [Logging, StreamHandler and standard streams](https://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams) – Chipmonkey Jun 25 '21 at 23:32

1 Answers1

1

While this question is tagged with flask and supervisord, the core issue is really how python's "logging" system works. By default, logger.info() messages are sent to stderr, not stdout, so flask and supervisor are doing what they're told (really flask hardly enters into it).

The python/logger portion has a good answer here: Logging, StreamHandler and standard streams

In short, you have to create a separate StreamHandler for stderr and stdout, and tell them what messages (INFO, DEBUG, ERROR, etc.) go to which ones.

There's working code in that accepted answer, so I won't repeat it here.

Chipmonkey
  • 863
  • 7
  • 18