Search code examples
javalog4jtestng

Capturing Log4j output when executing TestNG tests


I am executing TestNG tests , and the logging output is set to DEBUG, so in case of a failure I can get to inspect exactly what goes wrong.

The problem is that the output is extremely verbose, and it's bothering everyone when it runs . I would like to capture all Log4J logging events - which is easy - and only print them when the test fails. Also, I need to take into account @Before/@After methods and also print output for them.

Assuming that I already have a List of Log4J LoggingEvents , how can I print those only when the Test/After/Before methods fail?


Solution

  • Implement and register a org.testng.ITestListener and react on the callback methods.