Skip to content

Commit 60008ce

Browse files
authored
Update 26.6.2 Environment properties.md
1 parent bd5c02a commit 60008ce

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
### 26.6.2 Environment属性
2-
`<springProperty>`标签允许你从Spring `Environment`读取属性,以便在Logback中使用。
2+
`<springProperty>`标签允许你从Spring `Environment`读取属性,以便在Logback中使用。如果你想在logback配置获取`application.properties`中的属性值,该功能就很有用。该标签工作方式跟Logback标准`<property>`标签类似,但不是直接指定`value`值,你需要定义属性的`source`(来自`Environment`),也可以指定存储属性作用域的`scope`。如果`Environment`没有相应属性,你可以通过`defaultValue`设置默认值。
3+
```xml
4+
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
5+
defaultValue="localhost"/>
6+
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
7+
<remoteHost>${fluentHost}</remoteHost>
8+
...
9+
</appender>
10+
```
11+
**** `RelaxedPropertyResolver`用于获取`Environment`属性,如果以中划线的方式指定`source``my-property-name`),则所有relaxed变体都会进行尝试(`myPropertyName``MY_PROPERTY_NAME `等)。

0 commit comments

Comments
 (0)