-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log bootloader exceptions to a file #315
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this out and it works great. I just think that we can afford to log a little bit more information in order to make the file more useful. Try it out and see if you agree.
# Log the crash to a file for later analysis/recovery | ||
try: | ||
with open("last_crash.log", "w") as log_file: | ||
log_file.write(f"{time.ticks_ms()}: {err}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[required] As written this code provides very little information in the log file, just the timestamp and error message. Since we're not constrained to the screen here, we should at least print the traceback with:
sys.print_exception(err, log_file)
See https://docs.micropython.org/en/v1.20.0/library/sys.html#sys.print_exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
X-post from discord:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making that change. I'll look into the lint errors and merge this once I figure out what's up.
* In the case of a bootloader exception, log the exception to last_crash.log * Print the longer exception data to the file too
In the case of a bootloader exception, log the exception to
last_crash.log
To prevent the log from growing too much we just re-create the file, so only the last exception is ever saved.
This should resolve #140 and effectively re-implements the work that was closed in #302, though with only the last crash being recorded instead of a constantly-growing log file.