commons.logging1.1.1源代码研究(3)-- 日志器Log接口,SimpleLog实现
来源:互联网 发布:网络棋牌代理加盟赚钱 编辑:程序博客网 时间:2024/06/03 23:50
Log接口的定义如下:
其中主要的方法有:
is<Level>Enabled() -- 是否某个层次的日志开启
<Level>(Object message) -- 记录日志消息
<Level>(Object message, Throwable t) -- 记录日志消息和异常
其中<Level>指trace,debug,info,wran,error,fatal
SimpleLog实现:
simplelog.properties必须放在根路径下,是配置文件
配置前缀:“org.apache.commons.logging.simplelog.”
showlogname -- 是否显示日志名(true/false )
showShortLogname -- 是否显示短日志名(true /false)
showdatetime -- 是否显示时间(true/false )
dateTimeFormat -- 日期格式(默认为yyyy/MM/dd HH:mm:ss:SSS zzz)
defaultlog -- 指定默认日志的层次(info,debug等)
log.<类的完全路径名> -- 指定某一类的日志的层次
比如:org.apache.commons.logging.simplelog.log.Test.TestClass=debug
org.apache.commons.logging.simplelog.log.Test.TestA=info
那么Test.TestClass类的日志层次为debug;而Test.TestA的日志层次为info
SimpleLog一些重要代码分析:
(1)构造函数
其中while循环处实现了日志器层次的继承性,即:
(1)如果没有设置,则黙认为info
(2)如果对某一类明确了日志层次,如:org.apache.commons.logging.simplelog.log.Test.TestA(Test.TestA类),则使用这个明确的日志层次;如果没明确,则向上寻找org.apache.commons.logging.simplelog.log.Test;如果还没找到,则找org.apache.commons.logging.simplelog.defaultlog
(2)日志函数
这段代码很简单,要注意的是:
showlogname 显示的是完全的类名(包括包名);showShortLogname只显示类名
注意:SimpleDateFormat不是线程安全的,在多线程中必须同步
Date formats are not synchronized.
* It is recommended to create separate format instances for each thread.
* If multiple threads access a format concurrently, it must be synchronized
(3)具体的日志方法
先判断是否这个层次的日志开启,然后调用写日志方法
(4)得到资源的方法
AccessController的doPrivileged方法给了其中的代码“特权”,从而不用checkPermissions.
以下得到ClassLoader
以下是Thread类的getContextClassLoader()方法,可能会报SecurityException
- commons.logging1.1.1源代码研究(3)-- 日志器Log接口,SimpleLog实现
- commons.logging1.1.1源代码研究(4)-- JDK14Logger实现
- commons.logging1.1.1源代码研究(1)-- 组织结构
- commons.logging1.1.1源代码研究(2)-- 基本使用及配置文件
- 使用commons.logging中的SimpleLog显示调试和日志信息
- org.apache.commons.logging SimpleLog
- 在Spring中配置使用commons-logging的simplelog来输出日志
- 在Spring中配置使用commons-logging的simplelog来输出日志
- Rust日志学习(四)——simplelog
- commons-logging-1.1.1日志接口用法
- commons-logging-1.1.1日志接口用法
- java 日志接口 commons-logging
- 23.avi 【日志记录:log4j + commons log + jdk log】
- apache-comnons系列之commons-logging1.2 学习笔记
- python实现log日志
- 对象池commons-pool框架的研究以及源代码分析(一)
- 对象池commons-pool框架的研究以及源代码分析(二)
- 对象池commons-pool框架的研究以及源代码分析(三)
- DB2 数据的导入(Import) 导出(Export)(Load)
- 收集网上关于ActiveMQ ,JMS 的入门知识
- SAP XI/PI介绍
- 在.net remoting中使用自定义加密接收器
- 项目中的部分疑难杂症
- commons.logging1.1.1源代码研究(3)-- 日志器Log接口,SimpleLog实现
- linux下rwx权限数字解释
- 条件断点的设置和应用
- 程序员的爱情表白
- qq online;QQ在线
- 用PHP读取flv文件的播放时间长度
- Blog 式日历控件
- 整理
- 大家好啊