Graham Dumpleton wrote:
Yes, effectively the same as what I was doing. As I highlighted in prior
email though about request cache implementations, not sure it would
work correctly if an internal redirect occurred and both original handler
and target of internal redirect had registered request object. One needs
to use a stack for self.local.req and push/pop the request object on to
it.
Hm, very well. I never really considered the case of using the internal
redirect. I'm an "old school" mod_python user, so I'm not up on all the
new features apache2 brings to the table. Reading the docs, I would
suppose you could make use of req.prev somehow in these cases rather
than manually keeping a separate stack? E.g. in my free_req function,
do "self.local.req = self.local.req.prev" (assuming if there hasn't been
an internal_redirect, req.prev is None).
Your code would still work, but if anything was logged by the original
handler after the internal redirect had returned, the request object will
have been wiped out and it would not log through "req" but through
"apache.log_error()" instead.
Right, that's the intention: provide a reasonable fallback.
Graham
Nick wrote ..
Graham Dumpleton wrote:
Hopefully everyone follows what I am talking about. I will try and get
together a working example today of what I am talking about, but Nick,
you may want to consider posting your code and how you are using it
as it probably will not be too different.
Here's my sample code I was using. Very rough and unpolished, since I
ultimately decided not to use it. I haven't tried it in a while, but it
should more or less work. apache.py might contain the following code:
from logger import log_handler
Sample usage might look like the following (to steal your example from
a
subsequent email):
from mod_python import apache
import logging
log = logging.getLogger("mod_python")
log.warning("importing handler")
def handler(req):
apache.log_handler.set_req(req) # <-- here's the extra code
log.warning("running handler")
req.content_type = 'text/plain'
req.send_http_header()
req.write('hello\n')
return apache.OK
Notice that if you *don't* call set_req, logging will still work, but
not according to any special ErrorLog settings in your apache config
other than the global setting. Also, since log_handler is available,
you can change it's default formatting options somehow as a mod_python
directive in your apache config, or whatever else you want to set.
Nick