【发布时间】:2025-12-06 18:20:03
【问题描述】:
我有一个已配置为通过 Supevisord 运行的 python 烧瓶应用程序。 supervisor.conf 文件看起来像这样 -
[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)
问题是,当我通过 supervisord 运行应用程序时,它会将所有输出 - 信息、调试、错误等记录到 %(program_name)s_stderr.log 日志文件而不是 %(program_name)s_stdout.log 文件中。
我使用 python 的默认日志库将我的信息消息记录为 -
logger.info("Some info msg")
这种行为的原因可能是什么?
【问题讨论】:
-
添加redirect_stderr=true。在链接supervisord.org/subprocess.html中查找更多文档。
-
Flask 默认只记录到标准错误。您可以在此处找到有关此的详细信息:flask.palletsprojects.com/en/1.1.x/logging
-
这能回答你的问题吗? Logging, StreamHandler and standard streams
标签: python flask logging supervisord