26.6 Logback Extensions
Spring Boot包含许多可以帮助进行高级配置的Logback扩展.您可以在您的logback-spring.xml
配置文件中使用这些扩展.
Note
因为标准的
logback.xml
配置文件过早的被加载,所以不能在其中使用扩展.您需要使用logback-spring.xml
或自定义logging.config
属性.Warning
扩展不能与Logback的配置扫描一起使用.如果您尝试这样做,对配置文件进行更改将导致类似于下面记录的错误:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProperty],
current ElementPath is [[configuration][springProperty]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProfile],
current ElementPath is [[configuration][springProfile]]
Profile-specific Configuration
#### Environment Properties
`<springProperty>`标签能让你在使用Logback时使用Spring环境中的属性值.如果打算在你的Logback配置中使用`application.properties`中的属性,这将是非常有用的.
这个标签的工作原理同Logback的标准`<property>`标签工作原理类似.但是,不是指定value值,而是指定从环境中配置的`source`属性.如果需要将属性存储在本地范围之外的其他地方,可以使用
scope属性.如果需要回退值(如果环境中没有设置属性),您可以使用`defaultValue`属性.下面的示例展示了如何在Logback中使用公开属性:
Note
source
属性必须配置为短横线格式(例如my.property-name
).然而,添加到环境中的属性可以使用宽松的规则.