The indentation feature is a handy visual aid that enhances the logged messages readabilty. Debugging a large application is usually a difficult task. Dense and broad debug information harms the ability to spot a particular message. Another example where indentation is useful is that of a chain of method calls. Typical this kind of information is hard to follow just by looking at the debug output.
Logger helps making the debug output easier to read by providing indentation increment and decrement abilities. The user can programmatically instruct the logger to increment the indentation and the Logger will stick to this format in all subsequent logging calls until a decrement indentation command is issued. The idea is dead simple but sometimes the result can be dozens of minutes saved in looking for a particular information in the debug stack.
Let's see a practical example of how to use this feature.
1 public static void main(String[] args) { 2 ILogWrapper logger = new LogWrapperLog4JImpl("Sample logger title"); 3 4 logger.setDebugLogLevel(); 5 logger.debug("Sample log message 1..."); 6 logger.debug("Sample log message 2..."); 7 8 logger.increaseIndentation(); 9 10 for (int i = 1; i<=5; i++) 11 logger.debug("Iterating: cycle = " + i); 12 13 logger.decreaseIndentation(); 14 15 logger.debug("end log!"); 16 }
The code above produces the following output:
Jul 22 22:26:01,383 [main] DEBUG LogWrapperLog4JImpl - Sample log message 1... Jul 22 22:26:01,387 [main] DEBUG LogWrapperLog4JImpl - Sample log message 2... Jul 22 22:26:01,387 [main] DEBUG LogWrapperLog4JImpl - Iterating: cycle = 1 Jul 22 22:26:01,388 [main] DEBUG LogWrapperLog4JImpl - Iterating: cycle = 2 Jul 22 22:26:01,388 [main] DEBUG LogWrapperLog4JImpl - Iterating: cycle = 3 Jul 22 22:26:01,389 [main] DEBUG LogWrapperLog4JImpl - Iterating: cycle = 4 Jul 22 22:26:01,389 [main] DEBUG LogWrapperLog4JImpl - Iterating: cycle = 5 Jul 22 22:26:01,389 [main] DEBUG LogWrapperLog4JImpl - end log!