[GRADLE-2524] JAVA PLUGIN - test task - Setting of logger (using java.util.logging) is reset to defaults inside the test method (using TestNG) Created: 19/Oct/12  Updated: 12/May/16  Resolved: 12/May/16

Status: Resolved
Project: Gradle
Affects Version/s: 1.2
Fix Version/s: 2.14-rc-1

Type: Bug
Reporter: Filip Brychta Assignee: Pepper Lebeck-Jobe
Resolution: Fixed Votes: 8

Attachments: File sampleJavaProject.tar.gz    
Issue Links:
Related
Related to GRADLE-1252 output of TestNG listeners is not vis... Resolved
Related to GRADLE-2058 testNG listeners' system out/err is s... Resolved

 Description   

When logging from some test method (method annotated with @Test), setting of used logger is reset to defaults. So a default formatting is used and only INFO level and higher is logged. When logging from any other place in code (other than methods annotated with @Test), expected logging output is shown.

I attached a sample Java project to show the issue.

You can see from following output that in @BeforeSuite method all log levels are logged and log level of Root logger is set to FINEST. However in @Test method, only WARNING and SEVERE levels are logged and log level of Root logger is set to INFO.

Please see attached Java project for details.

Actual output:
##########################################################

                                            1. @BeforeSuite method ###############
                                              ##########################################################
                                              Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
                                              SEVERE: Severe level
                                              Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
                                              WARNING: Warning level
                                              Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
                                              FINE: Fine level
                                              Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
                                              FINER: Finer level
                                              Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
                                              FINEST: Finest level
                                              ---------------------------------------------------------
                                              ---------------------------------------------------------
                                              Properties of logger with name: 'myPackage.base.TestScript'
                                              Log level: null
                                              Log parent: java.util.logging.LogManager$RootLogger@56f449b8
                                              ---------------------------------------------------------
                                              ---------------------------------------------------------
                                              ---------------------------------------------------------
                                              ---------------------------------------------------------
                                              Properties of logger with name: ''
                                              Handler of '' logger: java.util.logging.ConsoleHandler@4013fba1
                                              Log level: FINEST
                                              Log parent: null
                                              ---------------------------------------------------------
                                              ---------------------------------------------------------
                                              My test > myPackage.tests.MyTest.testMethod STANDARD_OUT
                                              ##########################################################
                                            2. @Test method ######################
                                              ##########################################################

My test > myPackage.tests.MyTest.testMethod STANDARD_ERROR
Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
SEVERE: Severe level
Oct 19, 2012 5:50:18 PM myPackage.base.TestScript printAllLevels
WARNING: Warning level

My test > myPackage.tests.MyTest.testMethod STANDARD_OUT
---------------------------------------------------------
---------------------------------------------------------
Properties of logger with name: 'myPackage.tests.MyTest'
Log level: null
Log parent: java.util.logging.LogManager$RootLogger@56f449b8
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
Properties of logger with name: ''
Handler of '' logger: java.util.logging.ConsoleHandler@78497062
Log level: INFO
Log parent: null
---------------------------------------------------------
---------------------------------------------------------



 Comments   
Comment by Szczepan Faber [ 22/Oct/12 ]

Thanks for the detailed report.

This is related to GRADLE-1252 and GRADLE-2058. The fix may solve all 3 tickets.

The problem is that in TestNG, we start redirecting the output when the test starts. @BeforeSuite is triggered before the test starts and hence, its output is handled completely differently than typical test output. This is a valid bug and we plan to fix it at some point.

What is the use case you are trying to solve? Perhaps we can find a workaround?

Comment by Szczepan Faber [ 22/Oct/12 ]

Possible duplicates

Comment by Filip Brychta [ 22/Oct/12 ]

We found 2 possible workarounds:

  1. Configure the logger once more inside the first test method -> logging output is correct for all test methods in particular test suite.
  2. Overwrite test task and use Ant for launching tests
Comment by Szczepan Faber [ 22/Oct/12 ]

How do the workarounds work for you?

Comment by Filip Brychta [ 23/Oct/12 ]

#2 'Overwrite test task and use Ant for launching tests' is fine for us. So it's not a blocker for us, but we are planning to return to standard 'test' task once this issue is fixed.

Comment by Uladzimir Mihura [ 30/May/13 ]

It's true for a JUnit too:

https://github.com/gradle/gradle/blob/379def16e573f7a73a9b5ace9e5c2c69dbb2d0f2/subprojects/plugins/src/main/groovy/org/gradle/api/internal/tasks/testing/junit/JULRedirector.java

 LogManager.getLogManager().reset();  
 Logger.getLogger("").addHandler(new ConsoleHandler());

-vova

Comment by Dmitriy Korobskiy [ 30/May/13 ]

Have the same issue with JUnit. Discussed on the forum: http://forums.gradle.org/gradle/topics/unable_to_configure_java_util_logging_with_gradle_test_task

Comment by Gary Hale [ 01/Apr/16 ]

This has been reverted from 2.13 because it can break tests that rely on the old behavior. We will reintroduce for 2.14 with a toggle to enable the old/new behavior.

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