customizing a logging logger

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Sep 12 12:46:47 EDT 2007


On 11 Sep, 17:14, garyjefferson... at gmail.com wrote:
> What is the best way to do this, so that I don't have to manually put
> the self.ctx in the log string in hundreds of different places?
>

Another way is to generate your log messages via a factory method
which prepends the context: you can do this via a mixin, too.

def log_message(self, msg):
    return "%s: %s" % (self.ctx, msg)

Note also that in recent versions, an optional "extra" parameter can
be used, to pass info into the LogRecord.

See http://mail.python.org/pipermail/patches/2007-January/021535.html
which may be of some help - it's a similar use case.

Best regards,

Vinay Sajip




More information about the Python-list mailing list