[mod_python] usign the apache log ?

riesch at nieuw.nl riesch at nieuw.nl
Fri Jul 27 15:15:58 EST 2001

hi there,

what you can do is write your own log-class. I've done something like this:

class Log:
   def __init__(self, file, mode):
      if __debug__:
         delf.__descriptor = open(file, mode)
   def __del__(self):

   def append(self, string):
      self.__descriptor.write(string + "\n\n")
      # add some more information if you please

   def close(self):

   # Variables
   __descriptor = []

global log
log = Log("log.txt")

When you import this module, the log-instance will be known and be the same for every file that imports this module (the global takes care of this) and every write (wherever) happens in the same file.
To write stuff:

import from Log *

log.append("something happened")

I hope this helps,


On Fri, Jul 27, 2001 at 01:59:51PM +0200, Bo Lorentsen wrote:
> Hi ...
> I have been writing a system using this mod_python module, and it just
> work out fine for me. Its really a nice Python tool, keep up the good
> work. But (there is always a but :-)) I really like to be able to se
> more about what is going in inside my code, and I therefor looked for a
> way to write to the apache log file, but found nothing in mod_python.
> In the O'reilly book "Writing Apache modules with Perl and C" they have
> an example where they got a logger out of the Request class (or whatever
> they call it i Perl :-)). This don't seem to be the case in mod_python,
> and the only reference I could find to logging is the PythonLogHandler,
> and that don't sound like anything I could use.
> Is there something i have misunderstood, or is there a way do redirect
> stdout/err to the log or something fancy like that ?
> Thanks in advance !
> /BL
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list