当前位置:网站首页>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);}边栏推荐
猜你喜欢

Re18: Read the paper GCI Everything Has a Cause: Leveraging Causal Inference in Legal Text Analysis

日志导致线程Block的这些坑,你不得不防

69. Sqrt(x)x 的平方根

Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law

新一代开源免费的终端工具,太酷了

实战演练 | 在 MySQL 中计算每日平均日期或时间间隔

idea2021+Activiti【最完整笔记一(基础使用)】

你真的懂Redis的5种基本数据结构吗?

Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development

国外资源加速下载器,代码全部开源
随机推荐
Beijing suddenly announced big news in the Metaverse
STM32CubeMX配置生成FreeRTOS项目
实施敏捷过程中这些常见的问题你可曾遇到?
(C语言)文件操作
时刻铭记:总有一天你将破蛹而出
leetcode 剑指 Offer 63. 股票的最大利润
leetcode 剑指 Offer 52. 两个链表的第一个公共节点
ospf2双点双向重发布(题2)
Day113.尚医通:微信登录二维码、登录回调接口
Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
The thread pool method opens the thread -- the difference between submit() and execute()
唯物辩证法-条件论
Only after such a stage of development can digital retail have a new evolution
软考 系统架构设计师 简明教程 | 系统运行与软件维护
大数据产品:标签体系0-1搭建实践
(***重点***)Flink常见内存问题及调优指南(一)
【云原生】Kubernetes入门详细讲解
leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
【无标题】
If someone asks you about distributed transactions again, throw this to him