“JUL 执行原理和流程”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第11行: 第11行:
 
#Formatter 用来格式化 LogRecord
 
#Formatter 用来格式化 LogRecord
 
[[文件:JUL 流程示意图.png|无|缩略图|814x814像素]]
 
[[文件:JUL 流程示意图.png|无|缩略图|814x814像素]]
 +
 +
 +
 +
 +
=== 调试跟踪 ===
 +
{| class="wikitable"
 +
|+
 +
! colspan="2" |Logger logger = Logger.getLogger("io.github.jihch");
 +
|-
 +
! colspan="2" |return demandLogger(name, null, Reflection.getCallerClass());
 +
|-
 +
!LogManager manager = LogManager.getLogManager();
 +
!manager.demandLogger(name, resourceBundleName, caller);
 +
|-
 +
!manager.ensureLogManagerInitialized();
 +
!
 +
|-
 +
!// Read configuration.
 +
owner.readPrimordialConfiguration();
 +
 +
// Create and retain Logger for the root of the namespace.
 +
 +
owner.rootLogger = owner.new RootLogger();
 +
 +
owner.addLogger(owner.rootLogger);
 +
!
 +
|-
 +
!super("", null, null, LogManager.this, true);
 +
!
 +
|}

2023年2月23日 (四) 08:25的版本

https://www.bilibili.com/video/BV1iJ411H74S?p=10

日志原理解析

  1. 初始化 LogManager
    1. Log Manager 加载 logging.properties 配置
    2. 添加 Logger 到 logManager
  2. 从单例 LogManager 获取 Logger
  3. 设置级别 Level,并指定日志记录 LogRecord
  4. Filter 提供了日志级别之外更细粒度的控制
  5. Handler 处理日志输出位置
  6. Formatter 用来格式化 LogRecord
JUL 流程示意图.png



调试跟踪

Logger logger = Logger.getLogger("io.github.jihch");
return demandLogger(name, null, Reflection.getCallerClass());
LogManager manager = LogManager.getLogManager(); manager.demandLogger(name, resourceBundleName, caller);
manager.ensureLogManagerInitialized();
// Read configuration.

owner.readPrimordialConfiguration();

// Create and retain Logger for the root of the namespace.

owner.rootLogger = owner.new RootLogger();

owner.addLogger(owner.rootLogger);

super("", null, null, LogManager.this, true);