2

We have Spring Boot 2 application and are moving from Log4j to Logback. The whole thing went pretty smooth, but we're running in a small issue now.

When doing a gradle build with tests, just before the tests step/lifecycle changes to SUCCEEDED, gradle decides to print a whole amount of logging on the console. The issue seems to originate from Logback's ConsoleAppender: if I disable it, the issues disappears (but we also have no more logging). The printing occurs before Gradle starts generating junit XML test reports (inspected gradle debug log)

More mystifying: only a very small subset of packages is printed on the console:

  • org.springframework.amqp
  • com.zaxxer
  • org.mockserver.log
  • org.springframework.orm.jpa

All the printed logs are level INFO. If I add Logback loggers for these packages on level ERROR, no more logs printed on the console.

I can't figure out why Gradle decides to print these log entries on the console, after all the tests are done. I'd like to get rid of them.

We're on Java 17, using JUnit 5

junit-platform.properties

junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent

# For Hypersistence test
junit.jupiter.testclass.order.default=org.junit.jupiter.api.ClassOrderer$OrderAnnotation

Gradle versions used:

$ ./gradlew --version
------------------------------------------------------------
Gradle 8.0.2
------------------------------------------------------------

Build time:   2023-03-03 16:41:37 UTC
Revision:     7d6581558e226a580d91d399f7dfb9e3095c2b1d

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.6 (Amazon.com Inc. 17.0.6+10-LTS)
OS:           Mac OS X 13.2.1 aarch64

Same results with older version

$ gradle --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.6 (Amazon.com Inc. 17.0.6+10-LTS)
OS:           Mac OS X 13.2.1 aarch64

logback-test.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/default.xml"/>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger{10} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="TestLogAppender" class="application.TestLogAppender"/>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="TestLogAppender" />
    </root>
    <logger name="org.springframework.web" level="INFO"/>
    <logger name="org.springframework.jdbc" level="INFO"/>
    <logger name="org.apache.catalina" level="ERROR"/>
    <logger name="application" level="DEBUG"/>

</configuration>

gradle.properties (also contains a bunch of version properties)

org.gradle.logging.level=lifecycle

Example output with only all but 1 off the packages mentioned above not on level ERROR

$ ./gradlew clean build
Starting a Gradle Daemon, 1 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :application:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :application:compileTestJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :application:test
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2023-03-13 08:19:19,029 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:22,691 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:25,226 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:26,956 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:28,391 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:30,009 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:32,067 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:35,300 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:36,528 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:37,729 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:39,759 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2023-03-13 08:19:40,896 [SpringApplicationShutdownHook] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'

BUILD SUCCESSFUL in 1m 58s
21 actionable tasks: 21 executed
bvanseg
  • 63
  • 3

0 Answers0