当前位置:网站首页>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);
}边栏推荐
- Study Notes 11--Direct Construction of Local Trajectories
- 延迟队列MQ
- leetcode 剑指 Offer 46. 把数字翻译成字符串
- 读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》
- Redis Desktop Manager 2022.4.2 发布
- Flask之路由(app.route)详解
- 图像分析:投影曲线的波峰查找
- 20220728 Use the bluetooth on the computer and the bluetooth module HC-05 of Huicheng Technology to pair the bluetooth serial port transmission
- PyQt5快速开发与实战 8.1 窗口风格
- 宝塔搭建DM企业建站系统源码实测
猜你喜欢
随机推荐
无法定位程序输入点ucrtbase.abort于动态链接库api-ms-win-crt-runtime-|1-1-0.dll上
编译报错: undefined reference to `google::FlagRegisterer::FlagRegisterer解决方法
快解析结合象过河erp
2022/07/29 Study Notes (day19) Exception Handling
Unreal Engine Graphic Notes: could not be compiled. Try rebuilding from source manually. Problem solving
Use the R language to read the csv file into a data frame, and then view the properties of each column.
echart图表清空上一次数据
Unified exception handling causes ResponseBodyAdvice to fail
图像分析:投影曲线的波峰查找
Domino服务器SSL证书安装指南
百度推广助手遇到重复关键字,验证错误,怎么一键删除多余的
MySQL【运算符】
树莓派_烧写Raspberry官方镜像系统
包、类及四大权限和static
国外资源加速下载器,代码全部开源
LeetCode二叉树系列——94.二叉树的中序遍历
Always remember: one day you will emerge from the chrysalis
PyQt5快速开发与实战 8.1 窗口风格
0729放假自习
读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》









