• 日志异常分析记录


    1、ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:86 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:313)
        ... 18 more

    ch.qos.logback.core.joran.spi.Interpreter作用:扩展SAX DefaultHandler,根据预定义的模式调用各种操作(将xml配置文件翻译成日志对象)

    异常提示:没有spring配置属性适合的action(对应logback.xml中的 springProperty 属性)

    a、异常点:

    xml配置: <springProperty scope="context" name="logging.path" source="logging.file.path"/>

    对应代码:ch.qos.logback.core.joran.spi.EventPlayer#play,中正在解析该元素

    b、为什么springProperty没有对应的Action ?

    正常情况 List<Action> applicableActionList = ruleStore.matchActions(elementPath);应该是可以拿到springProperty对应的org.springframework.boot.logging.logback.SpringPropertyAction,然后进行spring属性解析的(即org.springframework.boot.logging.logback.SpringPropertyAction#getValue)

    那为什么ruleStore中没有呢,分析下ch.qos.logback.core.joran.spi.Interpreter#ruleStore初始化的逻辑,断点定位解析并新增rule代码:ch.qos.logback.core.joran.GenericConfigurator#buildInterpreter

    现象:加载rule的代码直接进入ch.qos.logback.classic.joran.JoranConfigurator中,并执行子类SpringBootJoranConfigurator扩展的springProperty相关性Action

    未执行的代码逻辑:org.springframework.boot.logging.logback.SpringBootJoranConfigurator#addInstanceRules

    c、为什么没有执行子类SpringBootJoranConfigurator的逻辑?

    分析日志加载逻辑定位到:ch.qos.logback.classic.util.ContextInitializer#autoConfig

    日志框架初始化看下会加载那些配置文件

    发现日志上下文初始化时会自动加载这些文件,而此时spring环境的配置信息还没有加载(断点验证)

     在ch.qos.logback.classic.util.ContextInitializer#configureByResource中使用了JoranConfigurator,此时的日志加载并不依赖spring环境的,所以在解析logback.xml时才会出现上述的报错

    logback-spring.xml 在Spring应用程序运行时生效(启动的时候生效)

    logback.xml 非Spring应用程序,(如main函数或测试类使用)logback.xml加载早于application.properties,

    PS:如果在logback.xml使用了application.properties中变量时,会获取不到导致异常,可以改成logback-spring.xml解决。

  • 相关阅读:
    vue2版本中slot的基本使用详解
    html+css+javascript+jquery+bootstarp响应式旅行社旅游平台网站模板(14页)
    C++项目:高并发内存池
    自己动手实现rpc框架(一) 实现点对点的rpc通信
    【模糊神经网络】基于matlab的模糊神经网络仿真
    单片机C语言实例:24、红外通讯
    Golang和Java对比
    微信自动化工具开发系列01_自动获取微信聊天信息(2022年7月可用)
    【Bond随你温故Azure Architecture】之HA&DR篇
    [小技巧]C# 反射
  • 原文地址:https://blog.csdn.net/qq_27789551/article/details/125609252