« Wow... Free Visual Studio versions | Main | Does JUnit need annotations? »

Controlling your log4j settings

Nick over at the System Mobile Web Log was having trouble with Log4J and his unit tests. Seems that he was getting the log4j.properties file from XDoclet, instead of the one he wanted.

Getting Log4J to pick up the right configuration file via the classpath is always annoying. Fortunately, there's an easy solution.

All you need to do is specify the log4j.configuration system property when you launch JUnit. The value should be the path to the log4j.properties or log4j.xml file you wish to use. Here's an example:


  <junit failureproperty="junit.failed" fork="true">
    <jvmarg value="-enableassertions"/>
    <batchtest todir="${log.dir}/tests" >
      <fileset dir="test/java" includes="**/*Test.java"/>
    </batchtest>
    <sysproperty key="log4j.configuration" value="file:test/java/log4j.properties" />
    <classpath location="build/test-classes"/>
    <classpath location="build/dist/${ant.project.name}.jar"/>
    <classpath location="lib/junit.jar"/>
  </junit>

p.To quote Nick: Hopefully this helps somebody else.

Post a comment


About

This page contains a single entry from the blog posted on June 30, 2004 9:29 AM.

The previous post in this blog was Wow... Free Visual Studio versions.

The next post in this blog is Does JUnit need annotations?.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35