How can I see the output of Log4J from a Java class starting with Ant?

When running the Java class through Ant, I had problems getting Log4J output, although log4.properties was in the class path. Document it here if anyone else has a problem.

eg.

<java classname="Hello" fork="true">      
    <classpath> 
    <fileset dir="${lib.dir}">
        <include name="**/*.jar"/>
    </fileset>     
    </classpath>
</java>
+3
source share
2 answers

This can be solved using the following:

<property name="log4j" value="file:///${basedir}/log4j.properties"/>
...
<java classname="Hello" fork="true">   
    <sysproperty key="log4j.configuration" value="${log4j}"/>
    <classpath> 
        <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
        </fileset>     
    </classpath>
</java>
+6
source

If you are interested in knowing where log4j is looking for configuration files, try setting the system property log4j.debug.

<java classname="Hello" fork="true">
  <sysproperty key="log4j.debug" value="true" />
  <classpath>
  </classpath>
</java>

This will print information about stderr where it searches for configuration files. It is briefly mentioned here in manual .

+2
source

Source: https://habr.com/ru/post/1714990/


All Articles