How to disable ch.qos.logback's own INFO messages in the run of the SpringBootTest during "mvn clean install"

1.1k Views Asked by At

After a discussion with @RasmusFaber, the author of the most upvoted answer to How to prevent logback from outputting its own status at the start of every log when using a layout, I decided to create a new question as the solution in that question is not applicable to my problem.


I am building a Spring Boot application by Maven.

I'd like to get rid of the log output from ch.qos.logback when I run mvn clean install. I want to disable the Logback's own status messages as shown below.

I believe I applied all the hints given here in StackOverflow (including the above mentioned question) and everywhere else. Still I cannot make my build silent.

Please notice that all the log lines are INFO, not even WARN. So it is not a problem of missing logback-access.xml file. The logback framework show an INFO message even when if does find the file - see the 3rd line. Furthermore there are other INFO messages which are just a garbage.

Logback's own status messages I want to disable

10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.6036202080949559352.0\logback-access.xml] using property "catalina.base"
10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.6036202080949559352.0\logback-access.xml] using property "catalina.home"
10:51:16,066 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
10:51:16,081 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
10:51:16,081 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@2831c178 - Registering current configuration as safe fallback point
10:51:16,081 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring

Wider context

(when I temporarily set all the log levels to DEBUG)

...
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ my-application ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.xxxx.MyUnitTest
...
2020-11-27 14:06:33.590 DEBUG 2656 --- [           main] .c.l.ClasspathLoggingApplicationListener : Application started with classpath: unknown

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-11-27 14:06:33.675  INFO 2656 --- [           main] c.xxxx.MyUnitTest   : No active profile set, falling back to default profiles: default
2020-11-27 14:06:33.676 DEBUG 2656 --- [           main] o.s.boot.SpringApplication               : Loading source class com.xxxx.MyApplication,class org.springframework.cloud.bootstrap.BootstrapApplicationListener$BootstrapMarkerConfiguration
2020-11-27 14:06:33.694 DEBUG 2656 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file 'file:/C:/workspace/my-application/target/test-classes/application.properties' (classpath:/application.properties)
2020-11-27 14:06:33.695 DEBUG 2656 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@280d4882
...
2020-11-27 14:06:41.791 DEBUG 2656 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Starting filters
...
2020-11-27 14:06:41.803 DEBUG 2656 --- [           main] o.apache.catalina.core.StandardContext   : Starting completed
############## START OF THE UNWANTED LOG ##############
14:06:41,811 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.4629575738537063162.0\logback-access.xml] using property "catalina.base"
14:06:41,811 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Could NOT configuration file [C:\Users\xxxx\AppData\Local\Temp\tomcat.4629575738537063162.0\logback-access.xml] using property "catalina.home"
14:06:41,812 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Found [logback-access.xml] as a resource.
14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - debug attribute not set
14:06:41,869 |-INFO in ch.qos.logback.access.joran.action.ConfigurationAction - End of configuration.
14:06:41,869 |-INFO in ch.qos.logback.access.joran.JoranConfigurator@62732be7 - Registering current configuration as safe fallback point
14:06:41,869 |-INFO in ch.qos.logback.access.tomcat.LogbackValve[null] - Done configuring
############## END OF THE UNWANTED LOG ##############
2020-11-27 14:06:41.876 DEBUG 2656 --- [           main] org.apache.catalina.mapper.Mapper        : Registered host [localhost]
2020-11-27 14:06:41.877 DEBUG 2656 --- [           main] o.apache.catalina.mapper.MapperListener  : Register Wrapper [default] in Context [] for service [StandardService[Tomcat]]
2020-11-27 14:06:41.878 DEBUG 2656 --- [           main] o.apache.catalina.mapper.MapperListener  : Register Wrapper [dispatcherServlet] in Context [] for service [StandardService[Tomcat]]
2020-11-27 14:06:41.878 DEBUG 2656 --- [           main] o.apache.catalina.mapper.MapperListener  : Register Context [] for service [StandardService[Tomcat]]
2020-11-27 14:06:41.879 DEBUG 2656 --- [           main] o.apache.catalina.mapper.MapperListener  : Register host [localhost] at domain [null] for service [StandardService[Tomcat]]
...
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 54.705 s - in com.xxxx.MyUnitTest

Directory structure:

\---src
    \---test
        +---java
        |   ...
        \---resources
            |   application.properties
            |   logback-access.xml
            |   logback-test.xml

application.properties

logging.level.root=ERROR
logging.level.org.springframework=ERROR
logging.level.ch.qos.logback=ERROR

logback-test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <logger name="org.springframework" level="ERROR"/>
    <logger name="ch.qos" level="ERROR"/>

    <root level="OFF">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

logback-access.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration />

POM.XML (only relevant lines left)

<project ...>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath />
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-access</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
0

There are 0 best solutions below