当前位置:网站首页>JCL learning
JCL learning
2022-07-30 10:12:00 【Rest in the summer】
The full name is Jakarta Commons Logging, which is a general log API provided by Apache.
It provides a unified interface for "all Java log implementations", and it also provides a log implementation, but the function is very weak (SimpleLog).So it is generally not used alone.He allows developers to use different specific log implementation tools: Log4j, Jdk's own log (JUL)
JCL has two basic abstract classes: Log (the base logger) and LogFactory (responsible for creating Log instances).

1. Getting started with JCL
- Build maven project
- Add dependency
commons-logging commons-logging 1.2 - Introduction code
public class JCLTest {@Testpublic void testQuick() throws Exception {// Get the log logger objectLog log = LogFactory.getLog(JCLTest.class);// output of logginglog.info("hello info");}}
Why do we use the log facade:
- Interface-oriented development, no longer depends on specific implementation classes.Reduce code coupling
- The project can flexibly switch the log framework by importing different log implementation classes
- Unified API, easy for developers to learn and use
- Unified configuration is convenient for project log management
2, JCL principle
1. Dynamically load the Log implementation class through LogFactory

2. An array of log implementations supported by the log facade
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. Get the specific log implementation
for(int i = 0; i < classesToDiscover.length && result == null; ++i) {result = this.createLogFromClass(classesToDiscover[i], logCategory,true);}边栏推荐
- 编译报错: undefined reference to `google::FlagRegisterer::FlagRegisterer解决方法
- 使用 Neuron 接入 Modbus TCP 及 Modbus RTU 协议设备
- 一个近乎完美的 Unity 全平台热更方案
- (***重点***)Flink常见内存问题及调优指南(一)
- BERT pre-training model series summary
- 606. Create a string from a binary tree (video explanation!!!)
- 代码随想录笔记_哈希_202 快乐数
- Jenkins 如何玩转接口自动化测试?
- A new generation of free open source terminal tool, so cool
- Day113. Shangyitong: WeChat login QR code, login callback interface
猜你喜欢
随机推荐
(C语言)文件操作
多线程--线程和线程池的用法
实战演练 | 在 MySQL 中计算每日平均日期或时间间隔
SST-Calib:结合语义和VO进行时空同步校准的lidar-visual外参标定方法(ITSC 2022)
debian10安装djando
时刻铭记:总有一天你将破蛹而出
梅科尔工作室-看鸿蒙设备开发实战笔记六—无线联网开发
Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
Version management of public Jar packages
shell script
Re18:读论文 GCI Everything Has a Cause: Leveraging Causal Inference in Legal Text Analysis
唯物辩证法-条件论
Use the R language to read the csv file into a data frame, and then view the properties of each column.
105. 从前序与中序遍历序列构造二叉树(视频讲解!!)
Soft Exam System Architect Concise Tutorial | Case Analysis | Requirement Analysis
CVTE校招笔试题+知识点总结
日志导致线程Block的这些坑,你不得不防
ThreadLocal内存泄漏是伪命题?
2022年顶会accepted papers list
Study Notes 10--Main Methods of Local Trajectory Generation









