Log4j 2
  1. Log4j 2
  2. LOG4J2-463

Configuration sample MyApp does not compile

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-rc1, 2.0
    • Component/s: Documentation
    • Labels:
      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);
          }
      }
      

        Activity

        Hide
        Matt Sicker added a comment -

        In patch form.

        Show
        Matt Sicker added a comment - In patch form.
        Hide
        Remko Popma added a comment -

        Thanks!

        Fixed in revision 1555488.
        Please verify and close.

        Show
        Remko Popma added a comment - Thanks! Fixed in revision 1555488. Please verify and close.

          People

          • Assignee:
            Remko Popma
            Reporter:
            Michael Diamond
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development