Greetings, 

I'm somewhat new to log4j and am having trouble getting my logging
output to print to the console. 

My log4j.xml file is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
 <layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern" 
         value="[%d{MMM dd, yyyy h:MM:ss aa zzz}] [%-5p] [%c %x %m]%n"/>
 </layout>
</appender>

<logger name="com.company">
  <level value="DEBUG" />
  <appender-ref ref="STDOUT" />
</logger>
        
<root>
  <level value="ERROR" />
  <appender-ref ref="STDOUT" />
</root>
</log4j:configuration>


I have some JUnit tests configured to execute in an Ant script.
My unit tests have the appropriate static data member:

Private static Logger logger = Logger.getLogger("com.company.MyTest");

And my logging statements are at the appropriate level:
Logger.debug("My debug statement");

I've placed log4j.jar in the compile and runtime classpath in my Ant
script:

My JUnit target is defined as such:

<target name="test.MyTest">
<junit printsummary="false" haltonfailure="true">
  <classpath refid="runtime.classpath"/>
  <classpath>
    <pathelement path="${build.dir}/library/classes"/>
    <pathelement path="${src.home}/core/main/com/company/core/testing"/>
  </classpath>
  <formatter type="plain"/>
  <test name=" com.company.MyTest " 
          haltonfailure="yes" todir="${build.dir}/report"/>
</junit>
</target>

Nothing is being printed to the console or the subsequent report file
generated by JUnit.

I've tried executing the Ant script and setting the location of the
log4j.xml file from the command line like so:
 ant -Dlog4j.configuration=<fully qualified path to log4j.xml file>

I've also tried using Ant's <sysproperty> element within the <junit>
task:
<sysproperty key="log4j.configuration" value="${log4j.xml}"/>

It is behaving like log4j cannot find the configuration file.

I know log4j is "working" because I can add the following line of code
to the unit test class and then I get logging statements printed to the
report file generated by JUnit.

BasicConfigurator.configure();

I've wasted too much time on this, so I thought I would post to the user
list for some help.

/robert


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to