Question

I have a server running nginx + UWSGI + python. UWSGI is running as a daemon with the flag set: --daemonize /var/log/uwsgi.log which logs all application errors.

I've noticed that on error if I use a python print statement it will write to the log but only on an error. The standard python logging library doesn't seem to affect the log in any situation.

How do I point the python logging libraries to use the UWSGI log?

Was it helpful?

Solution

use logging.StreamHandler as logging handler

OTHER TIPS

uWSGI is a wsgi server, and as such passes a stream in the environ dict passed to the application callable it hosts, using the key wsgi.errors. If you are writing a bare wsgi app, then writing to that stream should do the job. If you are using a framework that abstracts the wsgi interface out (and by the sound of it, you are, print would ordinarily write to sys.stdout, which gets closed on a daemonized process and would never make it to any log file), you will probably need to look into how that framework handles error logging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top