8

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

4

use logging.StreamHandler as logging handler

3 Comments

Although your answer was not detailed, it led me down the right path. This answer describes the method I used: stackoverflow.com/questions/1383254/…
@elkelk: Could you extend? I don't need the filters and tried to log with this method - it still doesn't print anything into the file.
I have similar problem but in regards with Docker containers. Take a look at stackoverflow.com/questions/35511839/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.