当前位置: 首页 > news >正文

随笔记录-springboot_LoggingApplicationListener+LogbackLoggingSystem

环境:springboot-2.3.1

加载日志监听器初始化日志框架

SpringApplication#prepareEnvironment
SpringApplicationRunListeners#environmentPrepared
EventPublishingRunListener#environmentPrepared
SimpleApplicationEventMulticaster#multicastEvent(ApplicationEvent, ResolvableType)
获取各类监听器(其中就有一个 LoggingApplicationListener 监听器),执行onApplicationEvent方法
 LoggingApplicationListener监听器

刚启动时,LoggingApplicationListener 就会执行 onApplicationEnvironmentPreparedEvent --> initialize
初始化日志框架

日志框架加载

LoggingApplicationListener#initialize
执行初始化

LoggingSystemProperties#apply(LogFile logFile) 中预置了一些系统属性,所以在一些日志中才有${XXX}引入有效,如${PID}
预置系统属性
LoggingApplicationListener#initializeSystem
加载具体日志系统
默认读取classpath日志配置文件,如logback日志系统默认配置(下图所示,读取第一个存在的配置;否则在此基础上,读取含-spring的对应配置,如logback-spring.xml);若是配置了logging.config,直接读取该配置文件。
在这里插入图片描述
读取默认配置文件读取spring后缀配置

logback日志

在logback-spring.xml中,使用${key:-默认值}形式表示获取变量key的值或者默认值(通过:-分隔),其中key就是普通字符串,像那些xxx.xxx.xxx形式的可以,本身名称就是这个(一般而言将json结构扁平化处理就是这种格式),并不是代表获取json结构(如Map嵌套)中对应层的值(刚开始以为可以这样的😂 看源码实际并不支持)

LogbackLoggingSystem#loadConfiguration
LogbackLoggingSystem#configureByResourceUrl
GenericConfigurator#doConfigure(java.net.URL)
… 经过一些列doConfigure重载方法
GenericConfigurator#doConfigure(java.util.List<ch.qos.logback.core.joran.event.SaxEvent>)
EventPlayer#play


Interpreter#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

这里根据标签获取对应的Action来解析属性,如xml中的标签对应着[configuration]、[configuration][property]、[configuration][appender]、[configuration][root]、[configuration][logger][appender-ref]等key,都有关联这个一个处理类

Interpreter#callBeginAction

property标签对应[configuration][property],关联PropertyAction类

PropertyAction#begin
InterpretationContext#subst
OptionHelper#substVars(java.lang.String, PropertyContainer, PropertyContainer)
NodeToStringTransformer#substituteVariable
NodeToStringTransformer#transform
NodeToStringTransformer#compileNode
NodeToStringTransformer#handleVariable

compileNode方法和handleVariable存在着递归:节点属于变量就会调用handleVariable;属于文本就直接拼接

NodeToStringTransformer#lookupKey

private String lookupKey(String key) {// 从ch.qos.logback.core.joran.spi.InterpretationContext.getProperty上下文中获取String value = this.propertyContainer0.getProperty(key);if (value != null) {return value;} else {if (this.propertyContainer1 != null) {// 从ch.qos.logback.classic.LoggerContext.getProperty上下文中获取value = this.propertyContainer1.getProperty(key);if (value != null) {return value;}}// 从系统属性System.getProperty获取value = OptionHelper.getSystemProperty(key, (String)null);if (value != null) {return value;} else {// 从系统环境变量System.getenv获取value = OptionHelper.getEnv(key);return value != null ? value : null;}}
}

logback出现“变量名_IS_UNDEFINED”情况,就是在handleVariable方法处理时,既没有变量值(lookupKey方法返回null),又没有默认值,就出现这个问题

http://www.lryc.cn/news/262800.html

相关文章:

  • 超级计算机与天气预报:精准预测的科技革命
  • 【uniapp小程序-分享】
  • 思幻二次元风格的工作室个人引导页源码
  • Rsync+notify文件实时同步工具
  • 小信砍柴的题解
  • 华为OD机试 - 跳格子3(Java JS Python C)
  • 每天五分钟计算机视觉:谷歌的Inception模块的计算成本的问题
  • 最新AI创作系统ChatGPT系统源码+DALL-E3文生图+支持AI绘画+GPT语音对话功能
  • 78-C语言-完数的判断,以及输出其因子
  • C# 使用FluentHttpClient请求WebApi
  • AXure交互及案列
  • 美颜SDK技术对比,深入了解视频美颜SDK的工作机制
  • OkHttp ,使用 HttpUrl.Builder 来添加查询参数并添加到请求对象
  • 图片速览 PoseGPT:基于量化的 3D 人体运动生成和预测(VQVAE)
  • Java对象结构
  • 基于redis的分布式锁实现方案
  • 基于JAVA+SpringBoot的线上智能问诊就医平台
  • adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
  • Pelee: A Real-Time Object Detection System on Mobile Devices(CVPR 2019)
  • 分布式理论 | RPC | Spring Boot 整合 Dubbo + ZooKeeper
  • 局域网其他pc如何访问宿主机虚拟机IP?
  • U8 语法制导翻译技术
  • 剑指offer A + B
  • gitlab(gitlab-ce)下载,离线安装
  • Jmeter接口测试断言
  • Temu、Shein、OZON测评自养号,IP和指纹浏览器的优缺点分析
  • 亚信科技AntDB数据库——深入了解AntDB-M元数据锁的相关概念
  • yolov5 deepsort-船舶目标检测+目标跟踪+单目测距+速度测量
  • Wireshark与其他工具的整合
  • DDD架构实践