0

For example:

# foo.py
foo = 1
bar = foo + 2
raise ValueError("FIXME")

python foo.py will generate something like

Traceback (most recent call last):
   File "/opt/app/foo.py", line 3
     raise ValueError("FIXME")

But what if I want to format this error message into json string {"exc_info": "Traceback...", "level": "ERROR", ...}. Can I do this using logging module? I don't what to use try/except and logging.exception.

aiven
  • 3,775
  • 3
  • 27
  • 52
  • 1
    It sounds like [this](https://stackoverflow.com/questions/6234405/logging-uncaught-exceptions-in-python) might be what you're looking for. You should be able to reformat the exception details in whatever way you like. – sj95126 Oct 31 '21 at 20:18
  • tnx, this is exactly what I needed – aiven Nov 01 '21 at 08:25

0 Answers0