springboot+logback进行日志输出时报current ElementPath is [[configuration][root][springProfile]]错误

logback使用了标签,获取到项目所处的环境是线上还是线下,根据这个来指定部分日志是否记录

  
       
 

但是在启动的时候报错,信息如下:

Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@118:32 - no applicable action for [springProfile], current ElementPath  is [[configuration][root][springProfile]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@119:39 - no applicable action for [appender-ref], current ElementPath  is [[configuration][root][springProfile][appender-ref]]

大概意思就是配置中没有找到标签,运气很好直接在springboot官方文档 https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-logback-extensions 中找到错误的原因:

Spring Boot includes a number of extensions to Logback that can help with advanced configuration. You can use these extensions in your logback-spring.xml configuration file.
[Note]
Because the standard logback.xml configuration file is loaded too early, you cannot use extensions in it. You need to either use logback-spring.xml or define a logging.config property.
[Warning]
The extensions cannot be used with Logback’s configuration scanning. If you attempt to do so, making changes to the configuration file results in an error similar to one of the following being logged:

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]]
  • 文档中将的很清楚,在springboot中包含了很多logback的扩展可以支持我们进行一些更高级的配置,比如逻辑判断
  • 如果使用logback.xml的话会使logback的配置加载的过早,无法使用扩展配置,需要修改logback的配置文件命名为logback-spring.xml或者在application.yml中定义logging.config指定logback.xml配置路径才能使用
  • 如果直接使用logback.xml配置方式的话会导致current ElementPath is [[configuration][springProfile]]等错误
    检查logback的命名发现项目中我名字为logback.mxl修改成logback-spring.xml后即可正常启动项目

你可能感兴趣的:(SpringBoot,logback,bug)