Skip to content
Advertisement

Control wsgiref simple_server log

I’m playing with wsgiref.simple_server to study the world of web servers.
I would like to control the log generated, but could not find anything about it in Python’s documentation.

My code looks like this:

JavaScript

Advertisement

Answer

wsgiref.simple_server.make_server by default creates a WSGIServer with WSGIRequestHandler:

JavaScript

WSGIRequestHandler here extends from BaseHTTPServer.BaseHTTPRequestHandler, where the logging magic turns out to be:

JavaScript

So it’s logging to stderr, actually, not to python logging module. You can override this in your own handler:

JavaScript

And pass your custom handler to the server instead:

JavaScript
Advertisement