Nic Ferrier wrote ..
> "Graham Dumpleton" <[EMAIL PROTECTED]> writes:
> 
> > That is, a global log handler instance is created once only. No instance
> per
> > request handler invocation.
> >
> > As you point out you need though to do caching of request objects. I
> have
> > previously posted on a safe way of doing this which works for internal
> > redirects. See:
> >
> >   http://www.modpython.org/pipermail/mod_python/2005-September/019071.html
> >
> > Other solutions I have seen people describe for request caching didn't
> > consider internal redirects properly. One also can't use thread local
> > storage as Python 2.3 doesn't support it.
> >
> > I have already pointed out how this sort of request caching will probably
> > be needed in mod_python 3.3 when various of the problems with the
> > module loading system hopefully will be fixed. Thus, any logger system
> > could harness what would then be builtin functionality at no cost.
> 
> This is interesting... how does it play with non-thread mpms?

Request cache code works in non-thread MPM as well, so just works,
nothing special to be done.

> > In terms of seamless integration, I am coming to the conclusion that
> > having mod_python internally create the single global log handler as
> part
> > of mod_python.apache being imported would be best. It only gets done
> > once, so insignificant overhead. Any code therefore doesn't need to
> > worry about that and just needs to get the logger and log their messages.
> > Beyond the creation of the one log handler, there is no overhead unless
> > handlers actually use logging, as the request caching will need to be
> > done for other reasons anyway associated with module importing.
> 
> I specifically rejected that option myself.
> 
> Programmers may or may not want to redirect logging through Apache. If
> mod_python used the system you describe there would either have to be:
>
> 1. config syntax to allow module 'logging' glue to be turned off
> 
> 2. removal of the apache log handler in all code that didn't want it
> 
> I don't like either of those.
> 
> I can think of lots and lots of reasons why code using logging
> wouldn't want to log to Apache.

I attached the log handler to the "mod_python" logger. Thus you have
to select that logger explicitly for it to be redirected to Apache. If a user
wants other loggers to redirect to Apache, within a PythonImport module
they could grab the global log handler instance from where it is kept
and add it against other loggers as they see fit. They could still also
create their own instance of the Apache log handler as well, as the
request cache isn't within the instance anyway and so doesn't matter
if there is more than one.

Thus, use of logging to Apache is optional.

> > Apart from the benefit of individual request handlers not having to create
> > log handler instances and all the cleanup problems with that etc, 
> 
> I don't believe it is onerous to have to specifically attach the
> Apache log handling glue in the handler.

I would suggest though that rather than add such code to every single
handler, use a separate PythonHandler phase to do the work. That way
it is in one spot only at least.

> > this logging mechanism is still usuable from global scope of a
> > module and messages logged at that point when a module is being
> > imported due to a request, will still be logged against the request
> > object.
> 
> Another advantage of your system is that the logging config file
> syntax could be used to assign loggers (I think).

I'm not too knowledgeable on the logging module, perhaps you could
explain that one further. Would it simply be a case of somehow pointing
at mod_python.apache.ApacheLogHandler and it would create an instance
automatically??

Graham

Reply via email to