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?
Logging to sockets will send log entries to the Unix socket /tmp/uwsgi.
Nginx implements a uwsgi proxying mechanism, which is a fast binary protocol that uWSGI can use to talk with other servers. The uwsgi protocol is actually uWSGI's default protocol, so simply by omitting a protocol specification, it will fall back to uwsgi .
Nginx is “a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache”. uWSGI is an implementation of the WSGI spec, which describes how a web server should communicate with a web app, which makes uWSGI also a type of web server.
The most basic way to run uWSGI is to tell it to start an HTTP server and import your application. If you're using the app factory pattern, you'll need to create a small Python file to create the app, then point uWSGI at that.
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.
use logging.StreamHandler as logging handler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With