stdlib/logging: Add full support for logging exception tracebacks.#660
Merged
dpgeorge merged 1 commit intomicropython:masterfrom Jul 21, 2023
Merged
Conversation
Member
|
This looks good, thanks. And it's CPython compatible (CPython also allows |
This commit allows you to pass an exception object in as the exc_info kwarg (CPython allows this), so logging exceptions can work even if the MICROPY_PY_SYS_EXC_INFO option is disabled in the firmware. 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. That's also fixed in this commit. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
b152c5f to
5329ef5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_INFOwhich is not always on by default.This PR allows you to pass an exception object in as the
exc_infokwarg (cpython allows this) so the following works regarless of the above build setting.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.