Reputation: 1629
I am trying to enable test logging with Gradle 4.2.1 and JUnit 4.
https://discuss.gradle.org/t/allow-slf4j-logging-during-junit-tests/24449
For some reason I can only see the INFO log levels and not above (WARN, ERROR). Anyone managed to set this to show all log levels during unit tests?
Thanks in advance.
dependencies {
compile group: 'org.slf4j', name:'slf4j-api', version: '1.7.21'
compile group: 'org.slf4j', name:'slf4j-simple', version: '1.7.21'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
...
test {
testLogging {
showStandardStreams true
exceptionFormat 'full'
logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<logger name="io.effectus.cqrs" level="INFO" additivity="false">
<appender-ref ref="CONSOLE" />
</logger>
<root level="WARN">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
Upvotes: 3
Views: 5658
Reputation: 12305
You have two SLF4J implementations on the classpath:
compile group: 'org.slf4j', name:'slf4j-simple', version: '1.7.21'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7'
The default for slf4j-simple is only INFO and above, this can be changed by configuring simplelogger.properties which you probably don't have.
So your issue, only seeing INFO and above, is probably caused by slf4j-simple taking precedence over logback-classic.
You mentioned in a comment that it works after upgrading to logback 1.2.3. Probably for some reason this takes preference over slf4j-simple now, but it's best to make sure you only have a single binding on the classpath.
Upvotes: 4