[Web-SIG] serving (potentially large) files through wsgi?

Manlio Perillo manlio_perillo at libero.it
Fri Dec 21 12:50:34 CET 2007

Graham Dumpleton ha scritto:
> On 21/12/2007, Chris Withers <chris at simplistix.co.uk> wrote:
>> Manlio Perillo wrote:
> [...]
>>> In mod_wsgi for nginx I now redirect sys.stderr to server log file (as
>>> suggested by Graham).
>> I've never really understood this desire to do *anything* with
>> sys.stderr. Writing to sys.stderr seems a very odd thing for any web
>> component to use, especially as python now has a fantastic logging package.
> I only ever suggested that sys.stderr be directed to the web server
> log file as a fallback to cope with third party Python modules which
> use it directly, or where the logging module defaults to outputing it
> there.


>>> However there are some problems.
>>> The log object has a fixed error level (NGX_LOG_ERR);
>>> this means that every message logged using this object will have this
>>> error level, even if I do, as example:
>>> log.info('just an info message')
>> I'm missing the relationship between this and python's logging package.
>> I'll note that the point you raise about why using sys.stderr for
>> logging sucks are things I agree with ;-)
> As I believe I have said before, I disagree with how you 

The "you" is "me", I presume :)

> are trying to
> make logging module output simply go to sys.stderr. If you want to
> preserve the concept of logging levels, then expose the internal web
> server logging function, including it accepting its concept of log
> level, and write a log handler for the logging module that uses it
> instead.

This is what I plan to do, in future.

But there is a problem.

Here is how logging.info is implemented:

def info(self, msg, *args, **kwargs):
     if self.manager.disable >= INFO:
     if INFO >= self.getEffectiveLevel():
         apply(self._log, (INFO, msg, args), kwargs)

As I can can see, logging level comparison is done in the high level 

The problem is that, in nginx, more sever errors have low integer 
values; in the logging module it is the contrary.

So, I'm not sure that I can just implement a logging handler...

> I can't get to the code right now, but have done exactly this with
> Apache, where one can install a custom Apache log handler that
> internally uses a SWIG'd binding for apache.http_log.ap_log_error().

I will give it a look, thanks.

 > [...]

Manlio Perillo

More information about the Web-SIG mailing list