使用Spring-Boot进行Logback配置实时重新加载(scan = true)

时间:2017-01-11 14:59:51

标签: java spring logging spring-boot logback

好的,我正在尝试配置一个logback-spring.xml

我的目标是在修改后自动重新加载配置文件。

这就是doc所说的:

FROM:

<configuration>
  ...
</configuration>

TO:

<configuration scan="true" scanPeriod="30 seconds">
  ...
</configuration>

毫无疑问,如果我不使用任何元素:

<springProperty>

OR

<springProfile>

实时重新加载没有任何问题。此外,如果我不使用scan="true" springProfilespringProperty也能正常运作。

所以我的结论是spring元素和scan彼此不喜欢。我从类型中得到错误:

16:29:39,101 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@12:125 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
16:29:39,102 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@16:109 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
16:29:39,102 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@19:64 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
16:29:39,103 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@33:29 - no applicable action for [springProfile], current ElementPath  is [[configuration][springProfile]]
16:29:39,103 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@34:70 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,103 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@35:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,103 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@36:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,104 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:12 - no applicable action for [append], current ElementPath  is [[configuration][springProfile][appender][append]]
16:29:39,104 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@39:10 - no applicable action for [file], current ElementPath  is [[configuration][springProfile][appender][file]]
16:29:39,104 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@42:70 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,104 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,104 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@44:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,105 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@46:12 - no applicable action for [append], current ElementPath  is [[configuration][springProfile][appender][append]]
16:29:39,105 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@47:10 - no applicable action for [file], current ElementPath  is [[configuration][springProfile][appender][file]]
16:29:39,105 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@50:70 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,105 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@51:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,106 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@52:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,106 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@54:12 - no applicable action for [append], current ElementPath  is [[configuration][springProfile][appender][append]]
16:29:39,106 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@55:10 - no applicable action for [file], current ElementPath  is [[configuration][springProfile][appender][file]]
16:29:39,106 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@58:70 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,106 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@60:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@62:12 - no applicable action for [append], current ElementPath  is [[configuration][springProfile][appender][append]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@63:10 - no applicable action for [file], current ElementPath  is [[configuration][springProfile][appender][file]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@66:70 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@67:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,107 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@70:12 - no applicable action for [append], current ElementPath  is [[configuration][springProfile][appender][append]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@71:10 - no applicable action for [file], current ElementPath  is [[configuration][springProfile][appender][file]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@74:53 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@75:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@78:54 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@79:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@84:23 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,108 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@85:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@91:37 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@92:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@95:54 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@96:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@99:54 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@100:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@103:23 - no applicable action for [root], current ElementPath  is [[configuration][springProfile][root]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@104:35 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][root][appender-ref]]
16:29:39,109 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@109:28 - no applicable action for [springProfile], current ElementPath  is [[configuration][springProfile]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@110:72 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@111:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@112:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@113:14 - no applicable action for [charset], current ElementPath  is [[configuration][springProfile][appender][encoder][charset]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@117:76 - no applicable action for [appender], current ElementPath  is [[configuration][springProfile][appender]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@118:13 - no applicable action for [encoder], current ElementPath  is [[configuration][springProfile][appender][encoder]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@119:14 - no applicable action for [pattern], current ElementPath  is [[configuration][springProfile][appender][encoder][pattern]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@120:14 - no applicable action for [charset], current ElementPath  is [[configuration][springProfile][appender][encoder][charset]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@124:54 - no applicable action for [logger], current ElementPath  is [[configuration][springProfile][logger]]
16:29:39,110 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@125:38 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][logger][appender-ref]]
16:29:39,111 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@128:23 - no applicable action for [root], current ElementPath  is [[configuration][springProfile][root]]
16:29:39,111 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@129:34 - no applicable action for [appender-ref], current ElementPath  is [[configuration][springProfile][root][appender-ref]]

正如我已经说过的,如果删除scan=true配置有效。如果我删除springProfiles和属性并离开scan=true配置再次起作用,但是有些东西不对吗?

我认为这样做很可能是不可能的,但有人找到了这样做的方法吗?

编辑:在我发布问题后的一周内,Spring更新了他们的documentation。我仍在寻找答案,我认为可能有一种方法可能在Spring属性和logback配置文件之间使用一些属性文件的中间层,因为logback文档说你可以将属性文件导入到配置中。但即便如此,springProfile的问题仍然存在。

1 个答案:

答案 0 :(得分:4)

Spring springProfile和springProperty元素存在扫描问题。

更多信息可在以下网址找到:

https://springframework.guru/using-logback-spring-boot/

问题记录在:

https://github.com/spring-projects/spring-boot/issues/7955