A simple example of using Logger

At the time, the Logger just offers one type of configuration: the LogLevel. The LogLevel can be set either by configuring the underlying logging platform (i.e. Log4J) or by the developer in runtime.

The following code snippet shows how to do it in runtime.

 1  public class SampleLogger {
 2  
 3      /**
 4       * @param args
 5       */
 6      public static void main(String[] args) {
 7              ILogWrapper logger = new LogWrapperLog4JImpl("Sample logger title");
 8              
 9              logger.setDebugLogLevel();
10              logger.debug("Sample log message 1...");
11              logger.debug("Sample log message 2...");
12      }
13  }
  • Line 7: The logger variable is of type ILogWrapper, the Logger provided generic interface. The logger is affected by a LogWrapperLog4JImpl object. The LogWrapperLog4JImpl type is an implementation of Logger that uses Log4J underneath.
  • Line 9: Here the LogLevel is set for 'DEBUG'. There are setter methods available for each of the LogLevels.
  • Lines 10 and 11: Two sample logging instructions. The logging methods receive Object-type parameters and output the argument conversion to string.

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...

In the future, as the need arises, there may be more configuration options added to Logger.