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]

Reply via email to