当前位置:网站首页>JCL 学习
JCL 学习
2022-07-30 09:28:00 【悠然予夏】
全称为Jakarta Commons Logging,是Apache提供的一个通用日志API。
它是为 "所有的Java日志实现"提供一个统一的接口,它自身也提供一个日志的实现,但是功能非常常弱(SimpleLog)。所以一般不会单独使用它。他允许开发人员使用不同的具体日志实现工具: Log4j, Jdk自带的日志(JUL)
JCL 有两个基本的抽象类:Log(基本记录器)和LogFactory(负责创建Log实例)。

1、JCL入门
- 建立maven工程
- 添加依赖
<dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> - 入门代码
public class JCLTest { @Test public void testQuick() throws Exception { // 获取log日志记录器对象 Log log = LogFactory.getLog(JCLTest.class); // 日志记录的输出 log.info("hello info"); } }
我们为什么要使用日志门面:
- 面向接口开发,不再依赖具体的实现类。减少代码的耦合
- 项目通过导入不同的日志实现类,可以灵活的切换日志框架
- 统一API,方便开发者学习和使用
- 统一配置便于项目日志的管理
2、JCL原理
1. 通过LogFactory动态加载Log实现类

2. 日志门面支持的日志实现数组
private static final String[] classesToDiscover =
new String[]{"org.apache.commons.logging.impl.Log4JLogger",
"org.apache.commons.logging.impl.Jdk14Logger",
"org.apache.commons.logging.impl.Jdk13LumberjackLogger",
"org.apache.commons.logging.impl.SimpleLog"};3. 获取具体的日志实现
for(int i = 0; i < classesToDiscover.length && result == null; ++i) {
result = this.createLogFromClass(classesToDiscover[i], logCategory,true);
}边栏推荐
- MySQL数据库题库
- XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
- 功能测试、UI自动化测试(web自动化测试)、接口自动化测试
- Study Notes 11--Direct Construction of Local Trajectories
- Functional Interfaces & Lambda Expressions - Simple Application Notes
- STM32CubeMX配置生成FreeRTOS项目
- 2022/07/29 Study Notes (day19) Exception Handling
- 大根堆的创建(视频讲解)
- BERT预训练模型系列总结
- HR团队如何提升效率?人力资源RPA给你答案
猜你喜欢
随机推荐
Basic operations of sequence table in C language
Four ways the Metaverse is changing the way humans work
转行软件测试,报培训班3个月出来就是高薪工作,靠谱吗?
(文字)无框按钮设置
Re21:读论文 MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real
105. Construct binary tree from preorder and inorder traversal sequence (video explanation!!)
快解析结合任我行crm
Re17:读论文 Challenges for Information Extraction from Dialogue in Criminal Law
Day113. Shangyitong: WeChat login QR code, login callback interface
Domino服务器SSL证书安装指南
Only after such a stage of development can digital retail have a new evolution
hcip06 ospf特殊区域综合实验
PyQt5-在窗口上绘制文本
Use the R language to read the csv file into a data frame, and then view the properties of each column.
学习笔记11--局部轨迹直接构造法
debian10 install djando
编译报错: undefined reference to `google::FlagRegisterer::FlagRegisterer解决方法
Using IN in MySQL will not go through index analysis and solutions
An article to understand service governance in distributed development
九九乘法表








![MySQL [operator]](/img/dd/2bf6ccd731299dc405bc06e03e1550.png)
