I have a logger formatter that currently formats all the usual logging levels into a json string. When I want to view the log, I use a javascript web page that converts json to into a table. Used formatter:
formatter = logging.Formatter(
'{"datetime":"%(asctime)s","level":"%(levelname)s","app":"%(app_name)s","module":"%(module)s",' +
'"line":"%(lineno)d","function":"%(funcName)s","msg":"%(msg)s"}'
)
It works great. Now I want to log exceptions using logging.exception ().
It seems that logging.exception does not provide dict elements that are in all other levels of logging.
How can I capture the stack trace that logging.exception provides, so I can convert it to a json compatible form that I create for all other log entries? I need logging.exception to grab a stacktrace and put it in the json "msg" element. If logging.exception does not provide other dict elements, such as asctime, level, etc., I can create them myself on the fly.
Royhb source
share