Michael Diamond created LOG4J2-463:
--------------------------------------

             Summary: Configuration sample MyApp does not compile
                 Key: LOG4J2-463
                 URL: https://issues.apache.org/jira/browse/LOG4J2-463
             Project: Log4j 2
          Issue Type: Bug
          Components: Documentation
            Reporter: Michael Diamond


The {{MyApp}} example application in the [Automatic 
Configuration|http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration]
 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:
{noformat}
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."); 
    }
}
{noformat}

{{Bar.java}} with fixes:
{noformat}
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);
    }
}
{noformat}



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to