`

关于commons logging

    博客分类:
  • java
阅读更多

Apache组织开发了一套用于支持Logging的Log4J,Java 1.4版本也引入了一套内置的 Logging框架,如果开发者想在这两套Logging系统之间自由的切换,该怎么办呢?答案就是,使用Commons Logging。 Commons Logging定义了一套抽象的Logging接口,用户可以通过配置,使这些接口指向任何一个已存在的Logging系统。

•使用抽象Logging接口
问题:
你在编写一个可以重复使用的库,需要写入Log信息,但你不想使你的Logging功能绑定在Apache Log4J或者JDK 1.4 Logging框架上。
解决方案:

public static void main(String[] args) {//自己替换[]

System.setProperty(”org.apache.commons.logging.Log”,
“org.apache.commons.logging.impl.Jdk14Logger”);
Log log = LogFactory.getLog(”com.discursive.jccook.SomeApp”);

if (log.isTraceEnabled()) {
log.trace(”This is a trace message”);
}

if (log.isDebugEnabled()) {
log.debug(”This is a debug message”);
}

log.info(”This is an informational message”);
  log.warn(”This is a warning”);
log.error(”This is an error”);
log.fatal(”This is fatal”);

}

LogFactory.getLog方法会根据底层环境返回一个适当的Log实现。如果用户想指定一个具体的Logging系统实现,可以设置org.apache.commons.logging.Log系统属性。例如:
System.setProperty(”org.apache.commons.logging.Log”,
“org.apache.commons.logging.impl.Log4JLogger”);
这样就会使用Log4J作为Logging系统。
org.apache.commons.logging.Log可以设定为:
•org.apache.commons.logging.impl.Log4JLogger  使用Log4J
•org.apache.commons.logging.impl.Jdk14Logger  使用JDK 1.4 Logging框架
•org.apache.commons.logging.impl.SimpleLog  使用Commons Logging内置的简单Log实现
其他:
总结一下,Commons Logging会按照下列顺序来指定具体的Log实现。
•如果定义了org.apache.commons.logging.Log系统参数,实用指定的Logging实现。
•如果在CLASSPATH里发现了Log4J,使用Log4J。
•如果使用的是JDK1.4,使用JDK1.4内置的Logging框架。
•如果都没有找到,则使用Commons Logging内置的简单Log实现。

分享到:
评论

相关推荐

    commons-logging.jar

    commons-logging-1.0-javadoc.jar, commons-logging-1.0.1-javadoc.jar, commons-logging-1.0.1.jar, commons-logging-1.0.2-javadoc.jar, commons-logging-1.0.2.jar, commons-logging-1.0.3-javadoc.jar, commons-...

    Commons logging API.chm

    Commons-logging API apache Commons logging API

    Apache Commons Logging 1.2

    Apache Commons Logging 1.2

    commons-logging-1.2_commonslogging_

    spring日志commons-loggingjar包,版本1.2

    spring-framework & commons-logging

    spring-framework & commons-logging spring-framework & commons-logging spring-framework & commons-logging spring-framework & commons-logging spring-framework & commons-logging spring-framework & ...

    commons logging

    apache commons logging1.1.2官方JAR包,供亲们下载~~

    commons-logging-1.1.3-API文档-中文版.zip

    赠送jar包:commons-logging-1.1.3.jar; 赠送原API文档:commons-logging-1.1.3-javadoc.jar; 赠送源代码:commons-logging-1.1.3-sources.jar; 赠送Maven依赖信息文件:commons-logging-1.1.3.pom; 包含翻译后...

    commons-logging-1.2

    commons-logging-1.2:java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory解决方法

    commons-logging-1.2-API文档-中文版.zip

    赠送jar包:commons-logging-1.2.jar; 赠送原API文档:commons-logging-1.2-javadoc.jar; 赠送源代码:commons-logging-1.2-sources.jar; 包含翻译后的API文档:commons-logging-1.2-javadoc-API文档-中文...

    commons-logging-1.1.3-API文档-中英对照版 (2).zip

    赠送jar包:commons-logging-1.1.3.jar; 赠送原API文档:commons-logging-1.1.3-javadoc.jar; 赠送源代码:commons-logging-1.1.3-sources.jar; 赠送Maven依赖信息文件:commons-logging-1.1.3.pom; 包含翻译后...

    开发工具 commons-logging-1.2

    开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发工具 commons-logging-1.2开发...

    commons-logging-1.2-API文档-中英对照版.zip

    赠送jar包:commons-logging-1.2.jar; 赠送原API文档:commons-logging-1.2-javadoc.jar; 赠送源代码:commons-logging-1.2-sources.jar; 包含翻译后的API文档:commons-logging-1.2-javadoc-API文档-中文...

    commons-logging-1.2-bin.zip下载

    这是commons-logging-1.2-bin.zip,有需要的朋友下载使用

    commons-logging-1.2.JAR开源包

    commonslogging1.2.jar是用来记录程序运行时的活动的日志记录工具,类似于JDBC的api接口,具体的的JDBCdriver实现由各数据库提供商实现

    commons-logging-1.1.1-API文档-中文版.zip

    赠送jar包:commons-logging-1.1.1.jar 赠送原API文档:commons-logging-1.1.1-javadoc.jar 赠送源代码:commons-logging-1.1.1-sources.jar 包含翻译后的API文档:commons-logging-1.1.1-javadoc-API文档-中文...

    JavaEE源代码 commons-logging-1.0.4

    JavaEE源代码 commons-logging-1.0.4JavaEE源代码 commons-logging-1.0.4JavaEE源代码 commons-logging-1.0.4JavaEE源代码 commons-logging-1.0.4JavaEE源代码 commons-logging-1.0.4JavaEE源代码 commons-logging-...

    commons-logging-1.1.3.jar

    common-logging是apache提供的一个通用的日志接口。用户可以自由选择第三方的日志组件作为具体实现,像log4j,或者jdk自带的logging, common-logging会通过动态查找的机制,在程序运行时自动找出真正使用的日志库。...

Global site tag (gtag.js) - Google Analytics