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

Regression in ProviderUtil.hasProviders for 2.9.0

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.9.0
    • Fix Version/s: 2.9.1
    • Component/s: Core
    • Labels:
      None

      Description

      With release of 2.9.0, log4j no longer finds it configuration when running in an ant task.

      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.util.ProviderUtil;
      import org.apache.tools.ant.BuildException;
      import org.apache.tools.ant.Task;
      
      public class AntTest extends Task {
          private static void logTest() {
              System.out.println("ProviderUtil.hasProviders() = " + ProviderUtil.hasProviders());
              System.out.println("LogManager.getContext() = " + LogManager.getContext());
              LogManager.getLogger(AntTest.class).warn("test warn");
          }
      
          public void execute() throws BuildException {
              logTest();
          }
      }
      

      This code when run with a log4j2.properties in the class path works fine with version 2.8.2, but when linked with 2.9.0 it fails:

      # using log4j-core-2.8.2.jar and log4j-api-2.8.2.jar
       [AntTest8] ProviderUtil.hasProviders() = true
       [AntTest8] LogManager.getContext() = org.apache.logging.log4j.core.LoggerContext@2d3379b4
       [AntTest8] 2017-09-05 14:57:41,854 WARN main [AntTest] test warn
      # using log4j-core-2.9.0.jar and log4j-api-2.9.0.jar
       [AntTest9] ProviderUtil.hasProviders() = false
       [AntTest9] ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
       [AntTest9] LogManager.getContext() = org.apache.logging.log4j.simple.SimpleLoggerContext@e4487af
      

      This may be related to this bug? https://issues.apache.org/jira/browse/LOG4J2-862

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rgoers Ralph Goers
                Reporter:
                aburgoyne Andre Burgoyne
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: