Disable Logback in SpringBoot

disable spring logging/logback
spring boot disable console logging
how to disable spring logging debug messages
spring boot logback.xml location
logback-spring.xml not working
spring boot log4j
spring boot inject logger
spring boot logs are not printing

It appears Springboot autoconfigures itself to use Logback with Tomcat. I would like to disable this and use the one I provide in my classpath.

The error message below.

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory) Object of class [org.slf4j.impl.SimpleLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>1.0.1.RELEASE</version>
    </parent>

    <groupId>com.fe</groupId>
    <artifactId>cloudapp</artifactId>
    <version>1.0.0</version>
    <name>Withinet-PaaS</name>
    <description>Develop your web applications in on our infrastructure and we will worry about administration and scalability of your app.</description>

    <properties>
        <java.version>1.7</java.version>
        <guava.version>16.0.1</guava.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.8</version>
    </dependency>
        <dependency>
        <groupId>com.withinet.cloudapp</groupId>
    <artifactId>slave</artifactId>
    <version>1.0.0</version>    
        </dependency>
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-core</artifactId>
            <version>6.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.0.Final</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>

        <!-- Spring Boot -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Hibernate validator -->

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>


        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <version>4.1.0.Final</version>
        </dependency>

        <!-- Guava -->

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>

        <!-- Java EE -->

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!--  Search -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>4.8.0</version>
        </dependency>

        <!--  Security 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>

        <plugins>

            <!-- Spring Boot Maven -->

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.withinet.cloud.Application</mainClass>
                    <layout>JAR</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

Add exclusion to both the spring-boot-starter and spring-boot-starter-web to resolve the conflict.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
  </exclusions>
</dependency>

How to Disable Console Logging in Spring Boot, Learn how to configure a Spring Boot application so that it does not log to the console, whether it is using Logback, Log4j2, or Java Util  How to Disable the Console Output for Logback. If our project uses Spring Boot starters, then the spring-boot-starter-logging dependency will be included as well. This particular starter configures Logback as the default framework and initially logs only to the console by default. This configuration can be customized by adding a

To add a better, more generic solution in Gradle (all instances will be excluded):

configurations {
    all*.exclude module : 'spring-boot-starter-logging'
}

From https://docs.gradle.org/current/userguide/dependency_management.html

Logging with Spring Boot, Learn how to log effectively with Spring Boot. We will look at Spring Boot Starter for Logging and Spring Boot starter for log4j2. Configuring Logback with Spring Boot. Logback is provided out of the box with Spring Boot when you use one of the Spring Boot starter dependencies as they include spring-boot-starter-logging providing logging without any configuration and can be altered to work differently if required.

To add a solution in gradle.

dependencies {
    compile ('org.springframework.boot:spring-boot-starter') {
        exclude module : 'spring-boot-starter-logging'
    }
    compile ('org.springframework.boot:spring-boot-starter-web') {
        exclude module : 'spring-boot-starter-logging'
    }
}

Spring boot console logging configuration example, -starter-logging — providing logging without any configuration that can be altered to work differently if required. There are two ways of providing your own configuration. Logback is provided out of the box with Spring Boot when you use one of the Spring Boot starter dependencies, as they include spring-boot-starter-logging — providing logging without any configuration that can be altered to work differently if required. There are two ways of providing your own configuration.

I do like this to solve my problem

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Configuring Logback With Spring Boot, Solution. To disable the logs, turn off the logging.level in both application.​properties and logback-test.xml. While there are a number of logging options for Java, the Spring Boot chose to use Logback for the default logger. Like many things in Spring Boot, Logback, by default, gets configured with sensible defaults. Out of the box, Spring Boot makes Logback easy to use.

I found that excluding the full spring-boot-starter-logging module is not necessary. All that is needed is to exclude the org.slf4j:slf4j-log4j12 module.

Adding this to a Gradle build file will resolve the issue:

configurations {
    runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
    compile.exclude group: "org.slf4j", module: "slf4j-log4j12"
}

See this other StackOverflow answer for more details.

Using Logback with Spring Boot, M3 so I assume some magic has been done somewhere to remove this dependency. Although it does exist if you are using (the current) version 1.5.6.​RELEASE . Tutorial on configuring Logback with Spring Boot. Contribute to lankydan/logback-with-springboot-config development by creating an account on GitHub.

Logback Configuration: Using XML, I want disable logback ConsoleAppender in Spring Boot (1.3.3.RELEASE),but not work, i search in issues and do it same. #1612 the  Logback – Disable logging in Unit Test. By mkyong | February 12, 2016 | Updated : February 8, 2017 | Viewed : 32,281 | +204 pv/w. While the unit test is running in the IDE, the Logback is showing a lot of configuration or status like this :

Spring Boot Test – How to disable DEBUG and INFO logs – Mkyong , It appears Springboot autoconfigures itself to use Logback with Tomcat. I would like to disable this and use the one I provide in my classpath. The error message​  How to configure logging in Hibernate – SLF4j + Log4j […] refer to this – How to configure logging in Hibernate – Logback Hibernate uses Simple Logging Facade for Java (SLF4J) to redirect the logging output to your […]

Configuring Logback with Spring Boot, This look at Spring Boot and Logback touches on how to configure your M3 , so I assume some magic has been done somewhere to remove  We can enable and disable the two categories independently. But, it makes sense to enable org.hibernate.SQL so that we know which SQL statement the parameter values relate to. 4. Activate Hibernate Statistics

Comments
  • It doesn't work for me because if I add those exclusions I get: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory.
  • Once you do this you will have to provide your own logger e.g log4j in your classpath. Why do you wish to exclude the default loggers from you application?
  • brilliant. awesome.
  • Is there a way to find out which jar declares logback without doing some 'exploration' in each jar? And, thanks! This helped me
  • mvn dependency:tree -Dverbose -Dincludes=spring-boot-starter-logging
  • That works for me and at least 7 other people. I don't think a problem with your configuration or environment should be a downvote for my solution (I assumed the downvote i received was from your comment - apologies if I'm wrong).
  • Have tried all other configs, this is the only one which worked for me
  • Thanks, for including this solution
  • This doesn't work, I still see spring-boot-starter-logging
  • Thanks for including a gradle solution!
  • I use slf4j and I can't see logback in my maven pom file.
  • Logback is an slf4j logger. Maybe you can share your pom?
  • I can't see any other slf4j implementations explicitly, so it must be coming in transitively. You can use tools like m2e (Eclipse) or "mvn dependency:tree" to visualize the dependencies. The Eclipse tooling also has a GUI for excluding dependencies (that's what you need to do - exclude one of them). It might be suffient to exclude "spring-boot-starter-logging" if you already have a complete slf4j (including the jcl bridge).
  • Thanks for your comment I figured it out by observing the dependency tree.