[mod_python] apache log handler

Graham Dumpleton grahamd at dscpl.com.au
Sun Oct 16 20:41:53 EDT 2005


Such things probably haven't been added for a couple of reasons.

The first is that mod_python up to 3.1.4 worked with older versions of
Python such as 2.2, but the "logging" module didn't exist in those older
versions of Python. With mod_python 3.2 there is opportunity to use
newer features as Python 2.3 or later will be a requirement, but ....

Second is that the intention is that mod_python be good at its core
functionality and not accumulate a lot of extra baggage. Given that the
logging interface is simple enough that users can write their own and
given that logging interfaces are often customised to specific
applications and therefore a generic one may not always be suitable
anyway, I am sure that some will argue that it shouldn't be in
mod_python.

What I might suggest is that you post up your code as an example on
the Python cookbook site.

  http://aspn.activestate.com/ASPN/Python/Cookbook/

Graham

Nic Ferrier wrote ..
> Does mod_python have a standard interface between python logging and
> Apache's logging? 
> 
> I can't see one included in the dist. I know lots of other people have
> written one. I've written one.
> 
> If there isn't one why isn't there one?
> 
> 
> Nic Ferrier
> 
> 
> PS for what it's worth here's mine:
> 
> # A log handler for mod-python
> 
> from mod_python import apache
> import logging
> 
> 
> class ProxyLogThing:
>     """A proxy for default Apache logging."""
> 
>     def __init__(self):
>         # No need to do anything.
> 
>     def log_error(msg, lvl):
>         apache.log_error(msg, lvl)
> 
> 
> class ApacheLogHandler(logging.Handler):
>     """A handler class which sends all logging to Apache."""
> 
>     def __init__(self, ref = None):
>         """
>         Initialize the handler (does nothing)
>         """
>         logging.Handler.__init__(self)
> 
>         if ref == None:
>             self.ref = ProxyLogThing()
>         else:
>             self.ref = ref
> 
>         # Set up the thing
>         self.level_mapping = { logging.CRITICAL: apache.APLOG.CRIT,
>                                logging.ERROR: apache.APLOG_ERR,
>                                logging.WARNING: apache.APLOG_WARNING,
>                                logging.INFO: apache.APLOG_INFO,
>                                logging.debug: apache.APLOG_DEBUG }
> 
>     def emit(self, record):
>         """Emit a record."""
>         self.ref.log_error(record.msg, record.lvl)
> 
> # End
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list