Another source of time for the logging package?

Ames Andreas Andreas.Ames at comergo.com
Wed Jun 1 08:49:39 EDT 2005


Skip Montanaro wrote:

> Before I get out my scalpel, has anyone found a non-invasive way to
> do this (or already done the surgery and would be willing to share
> it)?

While I'm not sure you would call the following 'non-invasive' I've
used it in a similar situation:

class MyLogRecord(logging.LogRecord):
    def __init__(*args, **kwargs):
        logging.LogRecord.__init__(self, *args, **kwargs)
        self.created = time_warp() # get the time you need

class MyLogger(logging.Logger):
    def makeRecord(self, *args, **kwargs):
        return MyLogRecord(*args, **kwargs)

Then I call

logging.setLoggerClass(MyLogger)

before the relevant loggers are created.


HTH,

aa


-- 
Andreas Ames | Programmer | Comergo GmbH | 
Voice:  +49 69 7505 3213 | andreas . ames AT comergo . com



More information about the Python-list mailing list