Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
Description
The MyApp example application in the Automatic Configuration section does not compile.
1. LogManager is not imported
2. logger is not static
3. !bar.doIt() conditional missing a close-paren
4. com.foo.Bar is similarly missing the LogManager import
Less critical, but the formatting/indentation of this example code is also poor, which could be confusing.
MyApp.java with fixes:
import com.foo.Bar; //Import log4j classes. import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class MyApp { // Define a static logger variable so that it references the // Logger instance named "MyApp". static Logger logger = LogManager.getLogger(MyApp.class.getName()); public static void main(String[] args) { // Set up a simple configuration that logs on the console. logger.trace("Entering application."); Bar bar = new Bar(); if (!bar.doIt()) { logger.error("Didn't do it."); } logger.trace("Exiting application."); } }
Bar.java with fixes:
package com.foo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class Bar { static Logger logger = LogManager.getLogger(Bar.class.getName()); public boolean doIt() { logger.entry(); logger.error("Did it again!"); return logger.exit(false); } }