I have 2 Spring Boot (1.4.1-RELEASE) console applications using Logback. Both configuration files are more or less identical, are located in my /src/main/resources folder and named logback-spring.xml.
Both projects include the maven dependency spring-boot-starter-logging in their pom.xml and fetch the logback Version 1.1.7.
The Spring Boot config as defined in both poms:
<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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath />
</parent>
<groupId>d.m.v.app-a</groupId>
<artifactId>my-app-a</artifactId>
<version>1.0.16-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
However, when running the applications one of them seems to fully ignore the logback configuration while the other picks it up like expected.
If I change the filename to logback.xml for the application that didn't work properly it suddenly works fine (even with the spring profiles that I'm using in them).
There is no apparent difference in any of the configurations involved (meaning the pom.xml, application.properties, etc.).
Does anybody know why that might be the case? I find this behaviour rather confusing.
By default, Spring Boot picks up the native configuration from its default location for the system (such as classpath:logback.
Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you are using the starters for assembling dependencies that means you have to exclude Logback and then include log4j 2 instead. If you aren't using the starters then you need to provide jcl-over-slf4j (at least) in addition to Log4j 2.
To configure Logback for a Spring Boot project via XML, create the logback. xml or logback-spring. xml file under the src/main/resources folder. The configuration in XML file will override the logging properties in the application.
Logback does not allow logging to be disabled from the command line. However, if the configuration file allows it, you can set the level of loggers on the command line via a Java system property.
I know it is somewhat old, but i had the same issue and figured it out... so the reason is simply that you have a logback.xml on your classpath (somewhere, not necessarily in your project which you start, in my case it was a dependency).
Take a look here: org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(LoggingInitializationContext, LogFile)
set a breakpoint, then you will see.
If spring boot doesn't find any logback configurations ("logback-test.groovy", "logback-test.xml", "logback.groovy", "logback.xml") on the classpath, logback-spring.xml will be picked up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With