简体   繁体   中英

How to call application.properties value in logback.xml file?

I want to call local location value(c:/temp) from application.properties file in logback.xml file.

currently i am specify location value in logback.xml itself, it's working fine.

logback.xml

<configuration>

    <property name="LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n" />
    <property name="APP_LOG_ROOT" value="c:/temp"/>
...
</configuration>

But i want to call value from application.properties file.

application.properties

''' log.location.value = c:/temp '''

what i have to change in logback.xml file.

Thank you.

Include the below snippet in your logback.xml :

<property resource="application.properties" />

This will let you refer properties in a standard way

Example: ${app.name}.

If you have configured my logback-spring.xml as per Spring Boot Documentation, this might be a better solution. Instead of calling the whole application.properties in your logback.xml file, you can refer to a specific property in the application.properties file like this:

<springProperty scope="context" name="APP_TIMEZONE" source="application.timezone" />

Then you can use the springProperty like this: ${APP_TIMEZONE} . This way you can call a specific value in the application.properties file.

<Pattern>
    %d{ISO8601,${APP_TIMEZONE}} [%thread] %-5level %logger{36} - %msg%n
</Pattern>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM