Write debug level logs on error – print detailed logging only in exceptional circumstances
TL;DR: Collect debug information in an in-memory buffer that is printed to the output when an error occurs (and quietly discarded in all other cases). I may have come …