Allow for print statements to log to device disk, crash reporting

As a developer, I would like to be able to fix bugs submitted by my players. I'd like to leave in a minimal set of logging to track important game state changes, and save those logs to a file, so that I can instruct users to send me the log file (or upload the file with the HTTP Network API).

Currently, the only way I can think of implementing this is with my own logging library that writes the data to disk with playdate.datastore. However, I would need to flush the buffer to disk every time I log, otherwise the buffer will be lost if the Playdate crashes.

If logging-to-disk were automatically supported by Playdate, then the OS-level crash handler (the one that displays the tumbling blocks, stack trace, and restart button prompt) could flush the buffer to disk, preserving the most recent logs while getting the performance gain of not having to flush after every log.

(If this got implemented, it would be nice to set some kind of limit on the logs collected, such as a rolling system where a new log file is created every 32kb and only 10 log files are retained, with the oldest one deleted as soon as the new one is started)

Additional wishful thinking: I doubt most players would want to mount their Playdate disk and find the log files to email me, so it would be cool to have the option for players to upload crash logs to Playdate's servers for official Catalog games!

Thanks!

1 Like

I think it would make more sense to use playdate.file to write directly to a file.