[GRADLE-2841] Logging from tools like log4j is not captured by TestNG execution Created: 16/Jul/13  Updated: 29/Jan/15  Resolved: 07/Nov/14

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.3-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Szczepan Faber
Resolution: Fixed Votes: 0


 Description   

Logging from tools like log4j/slf4j is not captured by TestNG execution

Problem: If someone uses standard logging tool like log4j the messages are not captured by Gradle, hence they don't appear in the test results (html/xml) and they are not passed onto the listeners. (btw. it works just fine for JUnit)

Symptoms:

  • some the standard output messages appear in the test results but some of them appear directly in the build log (log4j stuff)
  • log4j messages from test execution litter the build log without a way to turn them off

Investigation: For TestNG, we load all the test classes before triggering execution. If the class has a static Logger field (standard style of using a loggin toolkit), the static state gets initialized during class loading (TestNGTestClassProcessor.processTestClass), at this point the log4j initializes loggers and hooks up to the system output / error. Later, the test classes get executed (TestNGTestClassProcessor.stop) and the standard output/error redirector is started (CaptureTestOutputTestResultProcessor.started). However, now it's too late - log4j has already initialized and pushes the output directly to build log.

Possible solutions:

  • shuffle the listeners so that we start redirecting early enough. I've tried to spike it but it didn't quite work for me.


 Comments   
Comment by Gradle Forums [ 16/Jul/13 ]

Just tried out your sample, thanks.

It's log4j that is the problem. It's eagerly grabbing a reference to System.err so it bypasses our mechanism for capturing what is output. I'll raise a separate issue for this.

Comment by Gradle Forums [ 16/Jul/13 ]

Sorry, slf4j.

Comment by Gradle Forums [ 16/Jul/13 ]

Thanks for your response Luke, please paste bug reference here once it's created so I can watch it.

Comment by Sebastian Glahn [ 29/Jan/15 ]

The release notes of 2.3-rc-1 are marking this bug as solved but it looks like that is not true.

I'll raise a separate issue for this.

Can you provide a link to this issue please?

Generated at Wed Jun 30 12:32:58 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.