osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ignoring some default fields from SimpleJsonFormatter


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?