javaspringspring-bootlogback

Spring boot does not load logback-spring.xml


I have a sample Spring Boot application that uses Logback for logging. So I have logback-spring.xml next to the jar to configure the logging, however it does not work unless I specify it with logging.config, ex : logging.config=logback-spring.xml.

I have looked into Spring Boot ignoring logback-spring.xml where it suggests that it might be because there's already a spring.xml somewhere, but putting breakpoint on org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(LoggingInitializationContext, LogFile) shows that logFile is empty.

Am I doing something wrong here ?


Solution

  • By default, Spring will not look for resources outside the jar file. If you want to use an external logback configuration file, you must pass it's location when starting the jar:

    $ java -jar -Dlogback.configurationFile=/full_path/logback.xml app.jar
    

    Please, do not include the logback.xml into the final Jar file, it will cause multiple logback.xml files in the classpath.