Random thoughts on Logging
Tim writes
Log[...] things that you [...] care about[...].
I couldn’t agree more.
I’ve come across this guy, who wrote in this book that we should all stop commenting. Instead, if you needed to comment, log!
What an interesting idea, I thought, so I started doing it for a little project. Of course, comments on classes and methods remained, but all in-line comments were converted into log messages.
A few things became very apparent very quickly:
- Logging messages were littered with obscenities.
- The normal operation of the program generated a LOT of logging messages. This was OK, since the code was actually doing some complicated thing that I wasn’t fully used to.
- All the ‘easy’ part, that we don’t normally comment on, don’t get logged at all. This caused a few problems. Without those messages, though, the logging messages didn’t ‘flow’. That is, it would jump from one difficult part, without giving me any closure on what was happening, to another difficult part.
- If you include the working variables into your logging statements, you practically have effectively compiler-checked comments.
After a while, though, it became evident that this approach had its limitations and I relented, and my boss complained about the massive giganto logging file, but that’s a whole another story.
.J