You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Andre Burgoyne (JIRA)" <ji...@apache.org> on 2017/09/05 22:39:00 UTC

[jira] [Comment Edited] (LOG4J2-2033) Regression in ProviderUtil.hasProviders for 2.9.0

    [ https://issues.apache.org/jira/browse/LOG4J2-2033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16154451#comment-16154451 ] 

Andre Burgoyne edited comment on LOG4J2-2033 at 9/5/17 10:38 PM:
-----------------------------------------------------------------

Included below is my sample build.xml used for showing this bug:

{code:xml}
<project name="AntTest" default="antTest" basedir=".">
 <target name="clean">
  <delete dir="build"/>
 </target>

 <target name="compile">
  <mkdir dir="build" />
  <javac srcdir="src" destdir="build" includeantruntime="true">
   <classpath>
    <path refid="classpath.log4j.2.9" />
   </classpath>
  </javac>
 </target>

 <path id="classpath.log4j.2.9">
   <fileset dir="jars">
    <include name="log4j-api-2.9.0.jar"/>
    <include name="log4j-core-2.9.0.jar"/>
   </fileset>
 </path>
 <path id="classpath.log4j.2.8">
   <fileset dir="jars">
    <include name="log4j-api-2.8.2.jar"/>
    <include name="log4j-core-2.8.2.jar"/>
   </fileset>
 </path>

 <target name="antTest" depends="compile" description="run antTest">
  <taskdef name="AntTest8" classname="AntTest">
   <classpath>
    <pathelement location="build" />
    <pathelement location="conf" />
    <path refid="classpath.log4j.2.8" />
   </classpath>
  </taskdef>

  <taskdef name="AntTest9" classname="AntTest">
   <classpath>
    <pathelement location="build" />
    <pathelement location="conf" />
    <path refid="classpath.log4j.2.9" />
   </classpath>
  </taskdef>
  <AntTest8/>
  <AntTest9/>
 </target>
</project>
{code}

The full test project can be found [here|https://github.com/aburgoyne-mp/LOG4J2-2033]


was (Author: aburgoyne):
Included below is my sample build.xml used for showing this bug:

{code:xml}
<project name="AntTest" default="antTest" basedir=".">
 <target name="clean">
  <delete dir="build"/>
 </target>

 <target name="compile">
  <mkdir dir="build" />
  <javac srcdir="src" destdir="build" includeantruntime="true">
   <classpath>
    <path refid="classpath.log4j.2.9" />
   </classpath>
  </javac>
 </target>

 <path id="classpath.log4j.2.9">
   <fileset dir="jars">
    <include name="log4j-api-2.9.0.jar"/>
    <include name="log4j-core-2.9.0.jar"/>
   </fileset>
 </path>
 <path id="classpath.log4j.2.8">
   <fileset dir="jars">
    <include name="log4j-api-2.8.2.jar"/>
    <include name="log4j-core-2.8.2.jar"/>
   </fileset>
 </path>

 <target name="antTest" depends="compile" description="run antTest">
  <taskdef name="AntTest8" classname="AntTest">
   <classpath>
    <pathelement location="build" />
    <pathelement location="conf" />
    <path refid="classpath.log4j.2.8" />
   </classpath>
  </taskdef>

  <taskdef name="AntTest9" classname="AntTest">
   <classpath>
    <pathelement location="build" />
    <pathelement location="conf" />
    <path refid="classpath.log4j.2.9" />
   </classpath>
  </taskdef>
  <AntTest8/>
  <AntTest9/>
 </target>
</project>
{code}


> Regression in ProviderUtil.hasProviders for 2.9.0
> -------------------------------------------------
>
>                 Key: LOG4J2-2033
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2033
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.9.0
>            Reporter: Andre Burgoyne
>
> With release of 2.9.0, log4j no longer finds it configuration when running in an ant task.
> {code:java}
> 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();
>     }
> }
> {code}
> 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:
> {noformat}
> # 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
> {noformat}
> This may be related to this bug?  https://issues.apache.org/jira/browse/LOG4J2-862



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)