标签:
在缓存中的话直接拿来,没有的话进入newInstance方法,
public Log getInstance(String name) throws LogConfigurationException { Log instance = (Log) instances.get(name); if (instance == null) { instance = newInstance(name); instances.put(name, instance); } return instance; }
String specifiedLogClassName = findUserSpecifiedLogClassName();
这个方法首先在配置文件中查找org.apache.commons.logging.Log,有配置则返回,没有的话在系统属性中查找,还是没有则返回,就是如下4句
String specifiedClass = (String) getAttribute(LOG_PROPERTY);
specifiedClass = (String) getAttribute(LOG_PROPERTY_OLD);
specifiedClass = getSystemProperty(LOG_PROPERTY, null);
specifiedClass = getSystemProperty(LOG_PROPERTY_OLD, null);
然后根据specifiedClass创建一个log
如果没找到配置信息,按照如下顺序创建log,一旦成功就返回。
for(int i=0; i<classesToDiscover.length && result == null; ++i) { result = createLogFromClass(classesToDiscover[i], logCategory, true); }
private static final String[] classesToDiscover = { LOGGING_IMPL_LOG4J_LOGGER, "org.apache.commons.logging.impl.Jdk14Logger", "org.apache.commons.logging.impl.Jdk13LumberjackLogger", "org.apache.commons.logging.impl.SimpleLog" };
commons logging LogFactoryImpl的getInstance()方法
标签:
原文地址:http://blog.csdn.net/u011686226/article/details/46522433