ignoring some default fields from SimpleJsonFormatter

shradhattx at gmail.com shradhattx at gmail.com
Tue Aug 21 11:36:30 EDT 2018


I am using for my logger

handler.setFormatter(SimpleJsonFormatter(json.dumps))

It had some default fields - timestamp, function, line_number, module, level

and flexibility to provide extra fields in json log with use of 

   logger.info("my test message", extra={"anotherfield1": "test"})

I am using decorator functions so some of the default fields provided ex- function, line_number, module are not useful as it gives information on decorator module, line_number. 
I like to remove some fields from being logged while retaining others, keeping also the use of "extra"

This is what I tried -
     logging.Formatter('{"timestamp": "%(asctime)s.%(msecs)06d", "level":"%(levelname)s"}',
                        '%Y-%m-%dT%H:%M:%S')

The problem is that it doesn't print the fields given in 'extra'


How do I accomplish this?



More information about the Python-list mailing list