Spring-Boot Logging configuration when deployed as .war

I have a simple spring-boot application packaged as a .war file capable of being deployed to an external Tomcat container. I have logback.xml (below) in the classpath (/ WEB-INF / classes), however when deployed to Tomcat, the log is not written to the file.

<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <logger name="org.springframework.web" level="DEBUG"/> </configuration> 
+8
spring-boot tomcat war logback
source share
1 answer

I struggled with what could be the same problem - logging works fine with unit tests and runs the application's "main ()" method, but in tomcat it completely ignores my configuration.

It turns out that at startup tomcat sets the environment variable 'LOGGING_CONFIG' to describe the location of the file 'logging.properties'. This can be seen in tomcat / bin / catalina.sh or (.bat).

Spring Boot also reads the environment at startup, and as part of its intelligent configuration processing, I believe that it converts LOGGING_CONFIG to 'logging.config', which is a property that it uses so that you can override the location of its "logging configuration.

The problem is that he then tries to treat this value as a file name and load it (this is not the file name, but the Java system property that describes the file), but it does not work and does not initialize its registration correctly and continues with installing Tomcat by by default.

The solution is to make sure that the environment variable is set first, for example, something like (your IDE should have an option for this - in Intellij go to Run → Edit Configurations → Environment Variables → enter a name and value from the following):

 set logging.config=classpath:/logback.xml 

Spring Boot will use this in Tomcat's LOGGING_CONFIG preference and will work as expected.

So far, I have not been able to get this work from a configuration file such as application.properties, which means that this is a global setting for all applications deployed for this Tomcat instance.

EDIT: this is because environment variables override the local configuration in any case, which is in any other case, but that would be what you wanted: - (

EDIT 2: I can confirm that with Spring Boot 1.1.6 this problem has been handled - it is logged as a warning and it will continue to use the existing (and correct) logging configuration. Unfortunately, you cannot disable the warning itself inside your logback.xml file.

+21
source share

All Articles