4 ms·
There is a time and place to step through the code with a debugger, and there are also situations where a log file can show the "big picture" and display inform
by GnarfGnarf 4y ago
There is a time and place to step through the code with a debugger, and there are also situations where a log file can show the "big picture" and display information at a higher level. In the latter case, a log can show in minutes what would take hours to ascertain if stepping through line-by-line.
My app formats the trace log as HTML tables, and uses color to signal errors or invalid cases. Makes debugging fun.
Also, if diagnosing a problem on a customer's inaccessible machine, a log is indispensable.
Tip: close & re-open the file for each write, so the last and most important tail end of the log doesn't vanish if the app crashes.
- gpderetta 4y ago> Tip: close & re-open the file for each write That seems very expensive. Why not just use line buffering or even flush from a signal handler?
- GnarfGnarf 4y agoWell... we wrote this when we started with Windows 3.1. Besides it's only used in special circumstances when we're tracking down a bug.
- chrsig 4y ago> Tip: close & re-open the file for each write, so the last and most important tail end of the log doesn't vanish if the app crashes. It sounds like you're looking for fsync[0] [0] https://man7.org/linux/man-pages/man2/fdatasync.2.html https://man7.org/linux/man-pages/man2/fdatasync.2.html
- nyanpasu64 4y agoI think it's more important to fflush after logging data, so userspace buffers don't get lost if the app crashes. f[data]sync is only necessary to protect against system crashes.