It is important to ensure that log message are appropriate in content and severity. The following guidelines are suggested:
fatal - Severe errors that cause premature termination. Expect these to be immediately visible on a status console. See also Internationalization.
error - Other runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. See also Internationalization.
warn - Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. See also Internationalization.
info - Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. See also Internationalization.
debug - detailed information on the flow through the system. Expect these to be written to logs only.
trace - more detailed information. Expect these to be written to logs only.
LogFactory:抽闲类,获得Log类。 getFactory()先从缓存里取LogFactory,取不到再去找,然后放进缓存。其中找的这段代码如下
public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory"
protected static final String SERVICE_ID = "META-INF/services/org.apache.commons.logging.LogFactory"
public static final String FACTORY_PROPERTIES = "commons-logging.properties"
public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.LogFactoryImpl"
public static LogFactory getFactory() throws LogConfigurationException {
//1.系统环境变量里是否定义了LogFactory实现类,System.getProperty(FACTORY_PROPERTY)
//2.利用JDK1.3 开始提供的service 发现机制,会扫描classpah 下的SERVICE_ID文件,若找到则装载里面的配置,使用里面的配置
//3.Classpath下有FACTORY_PROPERTIES文件的话,看此properties里有无定义FACTORY_PROPERTY
//4.如果123找不到LogFactory实现类,使用FACTORY_DEFAULT
}
public abstract Log getInstance(String name)
throws LogConfigurationException;
public abstract Log getInstance(Class clazz)
throws LogConfigurationException;
public static Log getLog(String name)
throws LogConfigurationException {
return (getFactory().getInstance(name));
}
public static Log getLog(Class clazz)
throws LogConfigurationException {
return (getFactory().getInstance(clazz));
}
commons-logging-api.jar it does not include the wrapper Log implementations that require additional libraries such as Log4j, Avalon and Lumberjack。必然的commons-logging.jar依赖log4j,而commons-logging-api.jar不依赖任何包。