spring-bootlogbackspring-logback

How to properly configure logback using environment variables


I have this in my appication.properties file:

logs.home=/var/log

and on my logback-spring.xml:

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

    <property name="LOGS" value="${logs.home}" />

...
</configuration>

but when I start I have this problem: logs.home_IS_UNDEFINED


Solution

  • You need to use <springProperty>. Something like this:

    <springProperty scope="context" name="LOGS" source="logs.home"/>
    

    You can learn more in the relevant section of Spring Boot's reference documentation.