Prepend to logging message
Joan Miller
peloko45 at gmail.com
Sun Jan 10 04:47:52 EST 2010
On 10 ene, 03:27, Ishwor Gurung <ishwor.gur... at gmail.com> wrote:
> Joan,
>
> 2010/1/10 Joan Miller <pelok... at gmail.com>:
>
>
>
> > 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)
>
> > logger = logging.LoggerAdapter(logging.getLogger('foo'), ExtraLog())
> > ------------------
>
> Yep. Just subclass LoggerAdapter and override process(..)
> Read this:http://docs.python.org/library/logging.html#adding-contextual-informa...
> --
> Regards
> Ishwor Gurung
> Key id:0xa98db35e
> Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5
Any example to override process() ?
More information about the Python-list
mailing list