You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Robert Taylor <ro...@broadsource.com> on 2005/04/06 14:23:47 UTC

Ant, JUnit, and Log4j

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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Ant, JUnit, and Log4j

Posted by Ceki Gülcü <ce...@qos.ch>.
Hello James,

Just for your information, level values in config files are case insensitive.

At 02:46 PM 4/6/2005, James Stauffer wrote:
>I don't know if it matters but I use lower case for debug and info:
>     <level value="debug"/>
>
>Also adding -Dlog4j.debug might give you better info.

-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Ant, JUnit, and Log4j

Posted by James Stauffer <st...@gmail.com>.
I don't know if it matters but I use lower case for debug and info:
    <level value="debug"/>

Also adding -Dlog4j.debug might give you better info.

On Apr 6, 2005 7:23 AM, Robert Taylor <ro...@broadsource.com> wrote:
> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 


-- 
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Ant, JUnit, and Log4j

Posted by Ceki Gülcü <ce...@qos.ch>.
At 05:26 PM 4/6/2005, Jacob Kjome wrote:

>Look in Bugzilla.  There was some recent activity on this sort of 
>issue.  I had
>to do with Log4j, JUnit, and the ConsoleAppender not working with some code to
>correct it.  I haven't looked at the code's validity, but maybe this is the
>same issue?

Almost certainly not.

I suspect that the problem is due to the log4j.xml file not being placed 
correctly.
Robert, where are you placing the log4j.xml file? Is it in

   ${build.dir}/library/classes

or

   ${src.home}/core/main/com/company/core/testing

?

Which version of log4j are you using? JVM? Where is the log4j.jar file located?


-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Ant, JUnit, and Log4j

Posted by Jacob Kjome <ho...@visi.com>.
Look in Bugzilla.  There was some recent activity on this sort of issue.  I had
to do with Log4j, JUnit, and the ConsoleAppender not working with some code to
correct it.  I haven't looked at the code's validity, but maybe this is the
same issue?

BTW, have you tried forking the JUnit VM?  If you are worried about too much
forking slowing your tests, then use (This assumes Ant-1.6.2)...

<junit ... fork="yes" forkmode="perBatch">
...
</junit>

http://ant.apache.org/manual/OptionalTasks/junit.html

This "creates a VM for each nested <batchtest> and one collecting all nested
<test>s"


Jake

Quoting Robert Taylor <ro...@broadsource.com>:

> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org