Log4j配合Apache Commons Logging
来源:互联网 发布:java汉字编码转换 编辑:程序博客网 时间:2024/05/12 03:44
Apache的Common Logging是一个高层的日志框架,本身并没有实现真正的写日志能力,而是依赖其它的日志系统如Log4j或者java本身的java.util.logging。可以通过配置文件来设定最终使用log4j还是java.util.logging。
默认使用的是java.utl.logging,如果要使用Log4j,需要做一些配置,分3各步骤,
1. 建立log4j的配置文件,比如log4j.proiperties:
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
这些配置使得Log4j往Console输出Log信息。Log4j的详细配置,请参考apache的Log4j文档。
2. 建立commons-logging的配置文件,commons-logging.properties:
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory
org.apache.commons.logging.impl.Log4jFactory是commons-logging为了log4j所实现的一个LogFactory派生类。
3. 在代码中写上:
Log log=LogFactory.getLog(...);
然后就可以使用log直接写日志信息了,比如
log.debug(“...“)
log.error(“...“);
...
注意:这两个配置文件都必须在ClassPath下。
- Log4j配合Apache Commons Logging
- Apache Commons-logging+log4j配置
- Apache Commons-logging+log4j配置
- Apache Commons-logging+log4j配置
- Apache Commons-logging+log4j配置
- Apache Commons-logging+log4j配置
- apache commons-logging和log4j
- Apache Commons-logging+log4j配置
- Apache Commons-logging+log4j配置
- Apache Commons Logging日志与Log4j
- apache commons Logging与Log4j关系和只导入apache commons Logging为何能打印日志
- Commons-logging + Log4j 介绍
- commons-logging+log4j
- log4j 和commons-logging
- Commons-logging + Log4j
- Commons-logging Log4j整合
- commons-logging和Log4j
- commons-logging和Log4j?
- 当层遇到下拉框时
- Delphi中正常窗口的实现
- 在位图上写字
- 打造我的java向导型窗口
- vlc学习计划(2)---二进制包安装及使用
- Log4j配合Apache Commons Logging
- J2ME游戏中读入文本并存储在String数组中
- ScrapBook - 免费的CyberArticle
- J2ME学习笔记(一)
- Web Server程序编写学习笔记(四)源代码
- 幸福转瞬而逝
- J2ME学习笔记(二)
- 不与钱财过不去
- 怎样才能好起来?