Java: log4j Initialization Example
// Ref: http://logging.apache.org/log4j/docs/manual.html
1 2 import com.foo.Bar; 3 4 // Import log4j classes. 5 import org.apache.log4j.Logger; 6 import org.apache.log4j.BasicConfigurator; 7 8 public class MyApp { 9 10 // Define a static logger variable so that it references the 11 // Logger instance named "MyApp". 12 static Logger logger = Logger.getLogger(MyApp.class); 13 14 public static void main(String[] args) { 15 16 // Set up a simple configuration that logs on the console. 17 BasicConfigurator.configure(); 18 19 logger.setLevel(Level.DEBUG); // optional if log4j.properties file not used 20 // Possible levels: TRACE, DEBUG, INFO, WARN, ERROR, and FATAL 21 22 logger.info("Entering application."); 23 Bar bar = new Bar(); 24 bar.doIt(); 25 logger.info("Exiting application."); 26 } 27 }