commons.logging1.1.1源代码研究(1)-- 组织结构

http://commons.apache.org/logging/commons-logging-1.0.3/usersguide.html

一、介绍

    commons logging使应用程序不用绑定到特定的日志实现上,比如:可以使用Log4J或JDK14Logger等。以下是Apache commons的官方描述:

    The Logging Wrapper Library component of the Apache Commons subproject offers wrappers around an extensible set of concrete logging implementations, so that application code based on it does not need to be modified in order to select a different logging implementation.

 

二、包结构

1.org.apache.commons.logging包

   LogSource  -- deprecated,现在用LogFactory

   Log -- 日志器的接口,如果要使得自己的日志器可以被commons.logging使用,必须实现这个接口

   LogConfigurationException --  配置异常

   LogFactory -- 创建日志器的工厂类

 

2.org.apache.commons.logging.imp1包

   WeakHashtable  --  弱引用Hash表的实现(commons.logging默认内部使用)

   AvalonLogger、Jdk13LumberjackLogger、Jdk14Logger、Log4JLogger、LogKitLogger、NoOpLog、SimpleLog为一些日志器的实现

   ServletContextCleaner  --  用于在Servlet关闭时,消除相应的资源

3.commons-logging无依赖于其他包

 

三、高层视图

四、示例代码

1.导入

import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;

2.使用

private static Log log = LogFactory.getLog(CLASS.class);

3.重要方法

log.fatal(Object message); log.fatal(Object message, Throwable t); log.error(Object message); log.error(Object message, Throwable t); log.warn(Object message); log.warn(Object message, Throwable t); log.info(Object message); log.info(Object message, Throwable t); log.debug(Object message); log.debug(Object message, Throwable t); log.trace(Object message); log.trace(Object message, Throwable t); log.isFatalEnabled(); log.isErrorEnabled(); log.isWarnEnabled(); log.isInfoEnabled(); log.isDebugEnabled(); log.isTraceEnabled();

 

 

 

 

你可能感兴趣的:(jdk,log4j,object,logging,wrapper,deprecated)