简体   繁体   English

如何调用 logback.xml 文件中的 application.properties 值?

[英]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.我想从 logback.xml 文件中的 application.properties 文件调用本地位置值 (c:/temp)。

currently i am specify location value in logback.xml itself, it's working fine.目前我在 logback.xml 本身中指定位置值,它工作正常。

logback.xml 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 文件中调用值。

application.properties应用程序.properties

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

what i have to change in logback.xml file.我必须在 logback.xml 文件中更改什么。

Thank you.谢谢你。

Include the below snippet in your logback.xml :在您的logback.xml中包含以下代码段:

<property resource="application.properties" />

This will let you refer properties in a standard way这将让您以标准方式引用属性

Example: ${app.name}.示例:${app.name}。

If you have configured my logback-spring.xml as per Spring Boot Documentation, this might be a better solution.如果您根据 Spring 引导文档配置了我的 logback-spring.xml,这可能是更好的解决方案。 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:您可以在 application.properties 文件中引用特定属性,而不是在 logback.xml 文件中调用整个 application.properties:

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

Then you can use the springProperty like this: ${APP_TIMEZONE} .然后你可以像这样使用 springProperty: ${APP_TIMEZONE} This way you can call a specific value in the application.properties file.这样您就可以调用 application.properties 文件中的特定值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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