Print traceback without an exception
Hello, in CPython, there is a way to print a traceback outside of an exception, through traceback.print_stack() function. What would it take to add similar functionality to micropython?
stdlib/logging: Add full support for logging exception tracebacks.
I noticed recently that the current log.exception() function doesn't always print the tracebacks of the exception.
The current handling requires your build to be compiled with MICROPY_PY_SYS_EXC_INFO which is not always on by default.
This PR allows you to pass an exception object in as the exc_info kwarg (cpython allows this) so the following works regarless of the above build setting.
try:
run_func()
except Exception as ex:
log.exception("run_func failed", exc_info=ex)
Separately to that, currently even when sys.exc_info() is enabled, it's only printing the traceback to _stream = sys.stderr - not to the configured logging handlers. This means for instance if you've got a file log handler, it misses out on the tracebacks.
This PR also addresses this.
This looks good, thanks. And it's CPython compatible (CPython also allows
exc_infoto be a 3-tuple, but we don't need to support that).