• 日志异常分析记录


    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解决。

  • 相关阅读:
    HTML: css中的display属性
    五周年创作纪念日
    浏览器上写代码,4核8G微软服务器免费用,Codespaces真香
    Bootstrap-jqgrid学习(十六)
    konva系列教程3:自定义图形
    C语言程序设计算法题 -- lab07(1027 - 1030)
    android 13.0 在自定义系统服务中通过代码设置默认laucher动态切换
    ES6扩展运算符(...)
    Sentinel使用教程
    万物皆可“云” 从杭州云栖大会看数智生活的未来
  • 原文地址:https://blog.csdn.net/qq_27789551/article/details/125609252