import logging logging.basicConfig(level=logging.DEBUG) class Foo(object): def __init__(self): self.bar = "hello" def __getitem__(self, key): return getattr(self, key) f = Foo() # Outputs "DEBUG:root:hello" logging.debug("%(bar)s" % f) # Raises "TypeErorr: format requires a mapping" logging.debug("%(bar)s", f)