previous next TOC
MyApp first example (2 of 2)
package com.foo;
import org.apache.log4j.Logger;

public class Bar {
  static Logger logger = Logger.getInstance(Bar.class);

  public void doIt() {
     logger.debug("Did it again!");
  }
}

The output of MyApp is:

0    [main] INFO  MyApp  - Entering application.
36   [main] DEBUG com.foo.Bar  - Did it again!
51   [main] INFO  MyApp  - Exiting application.


The invocation of the BasicConfigurator.configure method creates a rather simple log4j setup. This method is hardwired to add to the root logger a ConsoleAppender. The output will be formatted using a PatternLayout set to the pattern "%-4r [%t] %-5p %c %x - %m%n".

By default, the root logger is assigned to Level.DEBUG.

The MyApp class configures log4j by invoking BasicConfigurator.configure method. Other classes only need to import the org.apache.log4j.Logger class, retrieve the categories they wish to use, and log away.

 

GET THE DOCS DIRECTLY FROM THE DEVELOPER
For up to date and detailed log4j documentation directly from the developer please consider The complete log4j manual.