Skip to content
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

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

chrisib
Copy link
Collaborator

@chrisib chrisib commented Nov 25, 2023

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.

Copy link
Collaborator

@mjaskula mjaskula left a 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")
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chrisib
Copy link
Collaborator Author

chrisib commented Jan 31, 2024

X-post from discord:

so the linter is now failing on files i haven't touched. looks like it's expecting newlines to exist where there previously were none.
should i be going through and correcting those files on all of my open MRs, or can github's linter be rolled back to the previous version that didn't complain so much?

Copy link
Collaborator

@mjaskula mjaskula left a 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.

@mjaskula mjaskula merged commit 2b6a59a into Allen-Synthesis:main Jan 31, 2024
2 of 3 checks passed
chrisib added a commit to chrisib/EuroPi that referenced this pull request Feb 2, 2024
* In the case of a bootloader exception, log the exception to last_crash.log

* Print the longer exception data to the file too
@chrisib chrisib deleted the bootloader-logging branch February 5, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Project Suggestion] Debug Logging
2 participants