title: Capturing Log4j output when executing TestNG tests
body: <p>I am executing TestNG tests , and the logging output is set to <code>DEBUG</code>, so in case of a failure I can get to inspect exactly what goes wrong.</p>
  
  <p>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 <code>@Before/@After</code> methods and also print output for them.</p>
  
  <p>Assuming that I already have a List of Log4J <code>LoggingEvent</code>s , how can I print those only when the <code>Test</code>/<code>After</code>/<code>Before</code> methods fail?</p>