Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-463

Configuration sample MyApp does not compile

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.0-rc1, 2.0
    • Documentation
    • 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);
          }
      }
      

      Attachments

        1. LOG4J2-463.patch
          7 kB
          Matt Sicker

        Activity

          People

            rpopma Remko Popma
            dimo414 Michael Diamond
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: