Prepend to logging message
Peter Otten
__peter__ at web.de
Sun Jan 10 05:26:55 EST 2010
Joan Miller wrote:
> How to prepend anything to a logging message? Is possible to do it
> from the dictionary object (ExtraLog) or is there is that override
> process() [1]?
>
> ------------------
> class ExtraLog(object):
>
> def __getitem__(self, name):
> if name == 'foo':
> result = 'testing'
> return result
>
> def __iter__(self):
> keys = ['foo',]
> keys.extend(self.__dict__.keys())
> return iter(keys)
format = "foo=%(foo)s " + logging.BASIC_FORMAT
logging.basicConfig(format=format)
logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
logger.error("yadda")
Is that what you want?
Peter
More information about the Python-list
mailing list