[mod_python] outputting to apache log

Graham Dumpleton grahamd at dscpl.com.au
Sun Jul 9 18:44:02 EDT 2006


greg wrote ..
> > I haven't used PythonLogHandler myself, but I suspect it doesn't do what
> > you think does.
> > 
> > Putting PythonLogHandler in your apache config will cause your handler
> > to be called by apache during logging phase, which is the second to last
> > phase - cleanup being the last. What you do in your handler is entirely
> > up to you, such as logging to a separate file, database, error log, or
> > whatever.
> > 
> > AFAIK there is no functionality exposed in mod_python that allows you
> to
> > interact with the access log, or if this is even possible.
> 
> Thanks for the reply Jim.
> 
> I assumed it was possible from this article by Gregory Trubetskoy:
> 
> http://www.onlamp.com/pub/a/python/2003/10/02/mod_python.html
> 
> "A mod_python connection handler leverages [..] Apache server facilities
> such as logging."

There is "req.log_error()" and "apache.log_error()" but their output
goes to the "error_log" file. I also don't know of anyway from
mod_python of making stuff go to the "access_log".

Remember the "access_log" has a specific format which can be changed
based on various Apache log directives and a lot of tools also expect to
process "access_log". Dumping arbitrary stuff in there may cause
problems for such tools. That is I presume why very basic logging
functions go to "error_log" instead. There may well be a Apache C API
for putting stuff in "access_log" but it is probably going to have a
very restricted interface and not allow arbitrary messages. You would
need to do some digging through Apache C API to find if such a one
exists and even if it is meant to be used by user code and Apache is
going to call it for you anyway.

> If there is no modpy specific way of doing it, is there a generic
> approach in apache to capture stdout from a script?

Anything sent to sys.stdout and sys.stderr streams may eventually end up
in "error_log" but the streams generally need to be flushed explicitly
to get them to come out at instant that they are used rather than
sometime later when the streams are flushed by something else.
This may dependent on platform though.

What are you trying to log, general debug logging or something
analogous to what is in "access_log" now but perhaps to some other
location?

Graham


More information about the Mod_python mailing list