Graham Dumpleton wrote:
Graham Dumpleton wrote ..

It is only recently that I realised that a nested function like that
could access stack variables of the enclosing function.


I should have added, "when the execution of the enclosing function has
already finished and the nested function is called at a later time". I'm
not that stupid that I didn't know the nested function could access data
in enclosing function when enclosing function hadn't returned yet. :-)

Anyway, I have attached an updated version of my log handler. This fixes
the issue with log levels that don't exactly map to any defined level.
Eliminates the explicit stack for storing request objects and in general
tries to make the module durable in the face of any module reloading
scheme for mod_python which exists now or which may exist in the future.

You can either use the default "mod_python" log it sets up, or create
explicit instances of ApacheLogHandler and add them against any log
within the hierarchy that you want.

Any feedback most welcome.

The quick and dirty test went well except when I tried to change the log level. Using setLevel(logging.DEBUG) had which had no effect. Then I remembered the apache LogLevel directive. I had "LogLevel warn" in my virtual host config, so log.info("some message") was not making it into the error log. The LogLevel directive is only available in the server config or virtual host context. Trying to configure logging in a .htaccess file will be a bit of a problem for users. This detail would need to be addressed in the documentation.

Using the following code also gives some interesting results:

from mod_python import apache
from mod_python.apache_log_handler import ApacheLogHandler
import logging

def handler(req):
  log = logging.getLogger()
  hdlr = ApacheLogHander()
  log.addHandler(hdlr)
  log.warning("running handler")
  req.content_type = 'text/plain'
  req.write('hello\n')
  return apache.OK

Each request will result in n + 1 log messages, where n is the total number of requests. Kinda cool but not really what people will want. This should also be highlighted in any documentation.

Regards,
Jim

Reply via email to