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

15 篇文章 0 订阅
2 篇文章 0 订阅

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

  <springProfile name="prod">
       <appender-ref ref="LOGSTASH"/>
 </springProfile>

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

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]]

大概意思就是配置中没有找到<springProfile>标签,运气很好直接在springboot官方文档 中找到错误的原因:

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后即可正常启动项目
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值