How to show log4j output in surefire test resports
Asked Answered
V

2

18

When a test fails in maven the surefire test report xml files in target/surefire-reports/TEST-<test-name>.xml only shows the Standard Output System.output or Standard Error System.err

When I use the jdk java.util.logging.Logger all the logging shows in the Standard Error <system-err> tag, but it does not show when I use log4j.

The logging with log4j is working fine through a FileAppender and a ConsoleAppender. It shows in the full console output, but not on the individual test report files.

  • Can I configure log4j to redirect its output to System.out so it shows in surefire rerports?
  • Can I tell surefire to also show the log4j debug logging?
Vasileior answered 7/12, 2010 at 18:5 Comment(2)
Can you clarify what you're asking for? Do you want debug enabled during tests? Do you want individual log files for each test?Clein
@cj91 The logging is working fine, but it would be great if each of the surefire report files showed the log output for its corresponding test, as it does when using java.util.logging.Vasileior
V
1

Update the surefire plugin version.

Using version 2.9 the log4j output appears in <system-out> when using the ConsoleAppender

Vasileior answered 30/8, 2011 at 17:5 Comment(0)
M
16
  • Option one:

    For standard logging (System.out/System.err), you can have the following output:

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.8.1</version>
    
            <configuration>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
            </configuration>
        </plugin>
    

    This will generate output files for each of the tests.

  • Option two:

    For a log4j configuration you can create a custom log4j.xml / log4j.properties and simply place it under src/test/resources.

Manque answered 30/8, 2011 at 15:6 Comment(2)
I was using surefire 2.6. After updating to 2.9 it works as expected leaving the rest untouched.Vasileior
The default log4j2 console appender configuration tends to lead to Corrupted STDOUT warnings (at least for versions 2.9 to 2.11) in newer versions of surefire. When this happens, mangled output ends up in files like 2019-06-13T21-39-26_964-jvmRun1.dump. Setting follow=true on the console appender solved it for us.Mauricemauricio
V
1

Update the surefire plugin version.

Using version 2.9 the log4j output appears in <system-out> when using the ConsoleAppender

Vasileior answered 30/8, 2011 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.