quarkus: Log Level configuration not working in Unit Tests
Describe the bug
When running unit tests (not @QuarkusTest) of a quarkus project, only severe log messages are printed, no matter what quarkus.log.level is configured. This can be reproduced with the reproducer code below or any fresh Kotlin Gradle Quarkus project created with code.quarkus.io.
E.g. if I run the following test
import org.junit.jupiter.api.Test
import java.util.logging.Logger
class ExampleLoggingTest {
private val logger = Logger.getLogger(ExampleLoggingTest::class.java.name)
@Test
fun testHelloEndpoint() {
logger.severe { "Log severe" }
logger.info { "Log info" }
logger.fine { "Log fine" }
logger.finest { "Log finest" }
}
}
with an application.properties file like this:
quarkus.log.level=TRACE
Only the following log message is printed:
Log severe
When I remove the following from the build.gradle file
test {
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
I then also get the INFO log and the format changes. The result is
Juli 31, 2020 9:13:29 AM org.acme.ExampleLoggingTest testHelloEndpoint
SEVERE: Log severe
Juli 31, 2020 9:13:29 AM org.acme.ExampleLoggingTest testHelloEndpoint
INFO: Log info
When running the same test as a @QuarkusTest, the logging works as expected. Still, unit tests are an important part of tests and function the same way.
Expected behavior
All log messages with a level higher than the one specified in the application.properties file should be printed in unit tests.
Actual behavior
Only severe messages are logged by default and only severe plus info messages are logged when removing the test {...} block from the build.gradle file.
To Reproduce Steps to reproduce the behavior:
- Download reproducer project and unzip it (or add the test shown above to any plain Quarkus Kotlin Gradle project from code.quarkus.io) 2020-07-31_tests-logging.zip
- Run
./gradlew check - Only the severe message is shown.
Configuration
quarkus.log.level=TRACE
Environment (please complete the following information):
- Windows 10
- Quarkus 1.6.1, 1.5.2, 1.4.1 (others not tested)
- Kotlin
- OpenJDK 11
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 17 (14 by maintainers)
Well, IMHO this is definitely a blind spot in Quarkus projects. See also: #7696
In my current project we also have yet to find out how to get proper log output from plain Junit5 tests. Once I/we find a good way I’d come up with a documentation PR.
@famod: I was able to get the log outputs by changing the test task in the gradle file to
And I created a
logging.propertiesfile in the rest/resources directory with the following contents:I hope this can help you.
It would be nice to add some documentation on how to get logging working in junit tests when testing quarkus code. I think this should be added to the Quarkus testing guide. At the moment unit tests aren’t mentioned there.