ice
ice copied to clipboard
Suggestion: optional rich tracebacks
Currently an unhandled exception just shows the standard plain Python traceback. It can be helpful for debugging to show more information, and the dependencies are already there. One method is this:
log = get_logger()
def excepthook(*exc_info):
log.exception("Uncaught exception", exc_info=exc_info)
sys.excepthook = excepthook
However this doesn't work on its own, and a helpful warning explains why:
/code/.venv/lib/python3.10/site-packages/structlog/dev.py:421: UserWarning: Remove `format_exc_info` from your processor chain if you want pretty exceptions.
Indeed, removing that processor gives nice rich tracebacks:
I'm not familiar with structlog, maybe there's a better official way to do this. I also don't know the motivation for having format_exc_info
and the consequences of removing it.
An alternative, more direct approach:
rich.traceback.install(show_locals=True)
This has pretty much the same effect, but it's not logging, and maybe that's a problem.
None of this should be the default behaviour as the tracebacks are huge and annoying when you don't want them, but maybe it could be enabled by a new env var in settings.py
or some kind of verbose/debug CLI argument.
We're not actually using the structured logging for anything, so this is probably the way to go. I'll determine priority next week once the upcoming ICE release is done.
I'm happy to take this on if people think this is still valuable :)
Seems worthwhile, what do you think @alexmojaki ?
Sure, why not.