Django应用无法记录uWSGI守护进程的Tornado日志问题排查
Hey there! Let's break down why your uWSGI daemon logs aren't showing up in your desired log files while Django's logs work just fine. I'll walk through the key causes and fixes based on your config:
1. uWSGI's Own Log Target Is Set to Syslog, Not a File
Looking at your uwsgi.yaml, you've configured:
log-syslog: uwsgi
This tells uWSGI to send all its core logs (startup messages, worker status, daemon management logs) to your system's syslog service, not the log file you configured in Django.
To route uWSGI logs to a file instead, replace that line with:
logto: /path/to/your/uwsgi.log # Use your actual desired log file path
2. Attached Daemon (tornading) Logs Aren't Being Captured
The attach-daemon command starts your tornading process as a child of uWSGI, but uWSGI doesn't automatically capture the stdout/stderr of this child process by default. That means tornading's logs won't show up in uWSGI's logs or Django's logs unless you explicitly set this up.
You have a few options here:
- Redirect tornading's output directly to a file:
attach-daemon: /opt/application/bin/tornading >> /path/to/tornading.log 2>&1 - Capture child process output to uWSGI's main log:
Add this line to your uwsgi.yaml to forward all child process logs to uWSGI's main log stream (which you've now set to a file withlogto):capture-output: True
3. Django Logging and uWSGI Logging Are Separate Systems
Remember: Django's LOGGING configuration only handles logs generated by Django itself (views, models, etc.). uWSGI's core logs and daemon logs are controlled entirely by uWSGI's own config—they don't use Django's logging handlers at all. You need to configure both systems independently to get all logs where you want them.
Quick Troubleshooting Checks
- Check syslog for missing uWSGI logs: Since you had
log-syslog: uwsgienabled, your uWSGI logs might be in system syslog files. On Debian/Ubuntu, look at/var/log/syslog; on RHEL/CentOS, check/var/log/messages. - Verify log file permissions: Make sure the user running uWSGI has read/write access to the directories where you're trying to write logs. Permissions issues are a common culprit for missing logs.
- Test uWSGI in foreground mode: Run uWSGI without daemonizing it first (remove any
daemonizeconfig if present) to see if logs appear in your console—this can help spot immediate errors like permission denied.
内容的提问来源于stack exchange,提问作者ffc

