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?

elkelk
  • 1,692
  • 2
  • 13
  • 20

2 Answers2

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.

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
4

use logging.StreamHandler as logging handler

roberto
  • 12,723
  • 44
  • 30
  • 4
    Although your answer was not detailed, it led me down the right path. This answer describes the method I used: http://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams – elkelk Nov 05 '11 at 23:28
  • @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. – Michel Müller May 19 '14 at 02:38
  • I have similar problem but in regards with Docker containers. Take a look at http://stackoverflow.com/questions/35511839/how-to-force-applications-stdout-logs-through-uwsgi – msgre Feb 24 '16 at 19:24