Logging - Art or Science?
Once upon a time some ignoramus wrote an article on Exception Handling and then anybody who could relate wonders humorously including frustration on why such an obvious concept is difficult to control even in large enterprises.
There is another factor which is considered even simpler but still not mastered - i.e. plain and simple “LOGGING”. Logging doesn’t even have multiple dimensions. Its plain purpose is
1) what to log,
2) when to log,
3) categorization,
4) Finally how to use what is logged.
Let’s look at one by one and the approach briefly:
As a reminder, following should help serve for “what-to-log” and the usage of “categories/levels”.
- During any software writing, it is elemental is to put log statements during a start of a method and at the end of method, code snippet, calculation or any atomic program. This is categorized as INFO. If during a specific calculation, there is a choice made such as IF/ELSE, or need to know which iteration in FOR-EACH the program is currently being executed, the statement with specific information is categorized as DEBUG. Sometimes TRACE is another level but can be ignored.
- WARN is something that causes a particular program to fail but not critical enough to call an error or requiring abort or termination of the function. For e.g. FOR loop failed in 100 out of 1000 iterations but it was programmatically designed that it doesn’t have to exit out of the loop for a particular failure. In real world scenario, consider Stock ticker feeds published to multiple terminals from a central server every fraction of a second. If a particular update doesn’t go through, it does not require any special handling as subsequent update is enough for the end user but at the same time needs to be recorded separately for analysis.
- ERROR is closely associated with Exception Handling and is categorized for any functional failure of a component but not necessarily shutdown of the complete system. It can be sub categorized as BUSINESS, SERVICE, SYSTEM failure. For more details refer to the blog alluded in the opening statement of this entry.
- FATAL is more simply the last line in the log file in the life of a process as the system shuts down as it encounters such a condition and requires urgent and immediate response to bring the system up.
There are popular frameworks such as LOG4J which are plugged into many software products as well as a standard for customized and in-house development in enterprises.
Other than using such already available framework, enterprises should just decide on creating configuration controls so that logging is useful and not taken for granted. This is the “how to use” part.
- For e.g. there should be a consistent standard on whether the logging is to be stored on flat files or in database.
- The configuration should be two fold - one switching the levels of logging - production does not require all levels and only ERROR or FATAL. This is “when-to” part. Lower environments could require DEBUG and so on. The second part is that whether one needs to log the Payload (the whole transaction) or just the header (key transaction information to help in tracing).
- Say there is an issue in production and error messages are pointing to an error of a particular system but details are not known on what is causing the error, here the configuration can be done to turn on the logging levels for DEBUG and INFO for 10 minutes after which it will switch back to ERROR. Since INFO/DEBUG gives a lot of output, only a small part is required to understand the process flow in detail and steps that lead to a particular point. This is how configuration, levels, log detail, everything comes in place and more the sophistication, merrier the analysis leading to a solution.
- A dynamic configuration options for the above could help ensuring system availability all the time. This can be achieved by ensuring the logging component (or logger) is separate from the main program and has an active listener that configures the way it logs.
These are quite trivial things that can be easily taken care off with simple guidelines, standards and governance in place. Whether it is ART or SCIENCE, it’s anybody’s guess.


