|Ned Batchelder : Blog | Code | Text | Site|
Log message style guide
» Home : Text
Created 9 December 2002, last updated 6 February 2003
One of the fit-and-finish issues all systems developers need to address is the text of log messages. This is a log message style guide.
Once your product ships, it will be in customers' hands. They will run it on their machines. You won't be around, and neither will your debugger. Log messages could be a big part of your customer's experience with your product, especially when something goes wrong. They could also be a big part of your experience with fixing problems at customer sites.
These log messages will be some poor customer's first view of you after a problem occurs. Make sure the messages make the customer feel better about the product, not worse. Part of it is writing professional English (or whatever language), and part is having the right attitude in the text.
Simply being consistent in your log messages will go a long way toward making them seem professional and authoritative. Below I give guidelines for wording, punctuation, and so on. Even if you don't use these guidelines, pick some rules, and follow them.
As a developer, remember that you will be debugging problems with only these log messages to go by. Something will go wrong at a customer site, and you will be sent a log session (more than likely incomplete). You will not have a debugger, you will not have access to the machine. You will have your log messages. Make sure they will be helpful to you.
Many programming environments provide logging facilities. If you have one, use it. If you don't have one, search the web for one you can use. If you can't find one, seriously consider spending two days to write one. They provide useful features like timestamping, run-time selection of logging detail and facilities, options for where to log (system console, log file, system event log, etc).
As developers, we have a rich environment in which to experience our code: the debugger. When a problem occurs, our first impulse is to fix it: dive into the debugger, understand what's happening, fix the code, recompile, no more problem. Except there could still be a problem: what if the same bug had happened at a customer site? Suppose you had to fix the bug with only the log messages to guide you? Would you have been able to?
Next time a bug appears, don't jump into the debugger. Read the log. What did it tell you? Think hard about what information could have been presented there but was not. How could you make it more useful?
The first thing you should do is change the log to provide the information (ubiquitous stringification can help a great deal here). Run the code again (with the bug). Make sure that the log really is better. Then you can go ahead and fix the bug.
Of course, it is impossible to make logs rich enough to be a complete replacement for a debugger. And maybe you don't want to put effort into improving your log. But using the log now will at least give you a sense of what your customers and support people (and likely, you) will be experiencing when the product is in the field.