previous next TOC
MyApp example 1 of 2
import com.foo.Bar;

// Import log4j classes.
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;


public class MyApp {

  // Define a static logger variable so that it references
  // the Logger instance named "MyApp".
  static Logger logger = Logger.getInstance(MyApp.class);

  public static void main(String[] args) {

    // Set up a simple configuration that logs on the console.
    BasicConfigurator.configure();

    logger.info("Entering application.");
    Bar bar = new Bar();
    bar.doIt();
    logger.info("Exiting application.");
  }
}

MyApp begins by importing log4j related classes. It then defines a static logger variable with the name MyApp which happens to be the fully qualified name of the class.

MyApp uses the Bar class defined in the package com.foo.

 

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.