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.
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.
----- 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]