customizing a logging logger

garyjefferson123 at garyjefferson123 at
Sat Aug 18 06:53:34 CEST 2007

Suppose I have some sort of context variable that I want to appear in
log messages.  E.g.:

logger = logging.getLogger("somelogger")
class SomeOp:
    def __init__(self, ctx):
        self.ctx = ctx
    def method1(self):"%s: here's a message", self.ctx)

What's the idiomatic way to abstract away the inclusion of self.ctx
from the calls in et al?  Is there some way I can
declare a

    def info(self): return

but have it insert the '"%s: " % self.ctx' bit for me in one place
instead of the dozens of places I currently do it in the class?


More information about the Python-list mailing list