Thanks for getting back to me Dennis.  I got to play around with your 
suggestions (but not for as long as I would of liked).  log4j is in test scope, 
commons-logging still compile.

Changing commons-logging.properties to use SimpleLog as you suggested does not 
produce any output for me.
Also, my Cobertura report reports I've hit my logging statements only when I 
set a logger in my test class explicitly:

>>    myObjectUnderTest.logger = new SimpleLog(this.class.name)
>>     myObjectUnderTest.logger.level = SimpleLog.LOG_LEVEL_DEBUG


I simplified my src/test/resources/log4j.properties to:

     log4j.rootLogger=DEBUG, stdout
     log4j.appender.stdout=org.apache.log4j.ConsoleAppender

I might be worth mentioning that my test classes are Groovy classes and the 
classes under test are Java?
Thanks


----- Original Message ----
From: Dennis Lundberg <[email protected]>
To: Maven Users List <[email protected]>
Sent: Thursday, March 5, 2009 4:53:34 PM
Subject: Re: [maven-user] Getting log4j output during unit tests

John Prystash wrote:
> I only depend on commons-logging, not log4j.  log4j is provided by my 
> container, which is included in the same assembly, so at runtime logging 
> works.

Yes, but your container is not available when surefire runs the tests,
so you need to add log4j as a test scope dependency in Maven, like you
have specified a few lines down.

> I have commons-logging at scope compile.  Another module that depends on the 
> module in question packages up an assembly that includes all runtime 
> dependencies, which implicitly includes commons-logging.
> 
> I added src/test/resources/commons-logging.properties as you suggested and 
> then log4j in test scope:
> 
>     <dependency>
>       <groupId>log4j</groupId>
>       <artifactId>log4j</artifactId>
>       <version>1.2.14</version>
>       <scope>test</scope>
>     </dependency>
>    
> With or without the additional surefire configuration referencing 
> log4j.properties, I unfortunately don't see any output.
> I could be missing something fundamental here with how these libraries work 
> by chance.

Just to make sure commons-logging is working for you, try this.

Replace the line in commons-logging.properties with this one, to use the
internal simple logging implementation available in commons-logging:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

If that gives you output, then the problem lies with the log4j
configuration.

> 
> 
> 
> ----- Original Message ----
> From: Dennis Lundberg <[email protected]>
> To: Maven Users List <[email protected]>
> Sent: Wednesday, March 4, 2009 5:50:41 PM
> Subject: Re: [maven-user] Getting log4j output during unit tests
> 
> Do you have both commons-logging and log4j as dependencies in your
> project with the scope test?
> 
> You could try to add the file src/test/resources/commons-logging.properties
> with the following single line in it:
> org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
> 
> This tells commons-logging to explicitly use log4j as the logging
> implementation.
> 
> John Prystash wrote:
>> Hi, I have some logging statements in my classes under test that would I 
>> like to have run during my unit tests.
>>
>> I put a simple log4j.properties file under src/test/resources:
>>
>>     log4j.rootLogger=DEBUG, stdout
>>     log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>>     log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>>     log4j.appender.stdout.layout.ConversionPattern=%-5p [%t][%d{ISO8601}] 
>> [%C.%M] - %m%n
>>    
>> When I run mvn test, the file ends up in target/test-classes like I'd 
>> expect, but I see no output from the logging statements when my tests run.
>>
>> There is no src/main/resources/log4j.properties file to conflict with, but I 
>> then explicitly configured the surefire plugin to use log4j.properties:
>>
>>      <plugin>
>>         <groupId>org.apache.maven.plugins</groupId>
>>         <artifactId>maven-surefire-plugin</artifactId>
>>         <version>2.4.3</version>
>>         <configuration>
>>           <redirectTestOutputToFile>true</redirectTestOutputToFile>
>>           <systemProperties>
>>             <property>
>>               <name>log4j.configuration</name>
>>               <value>file:target/test-classes/log4j.properties</value>
>>             </property>
>>           </systemProperties>
>>         </configuration>
>>       </plugin>
>>
>> With no change. The *output.txt files for my tests were empty.
>>
>> I added the following statements to my test setup, I get some output:
>>
>>     myObjectUnderTest.logger = new SimpleLog(this.class.name)
>>     myObjectUnderTest.logger.level = SimpleLog.LOG_LEVEL_DEBUG
>>
>> My loggers are defined with:
>>
>>     private Log logger = LogFactory.getLog(this.getClass());
>>
>> I'm using commons-logging-1.1.1.jar.
>>
>> Thanks in advance for any insight.
>>
>>
>>      
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
> 
> 


-- 
Dennis Lundberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


      


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to