Tomcat源代码学习日记(2004-09-30 11:44)

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Tomcat的log

在Catalina 的start中

public void start() {

if (server == null) {

load();

}

long t1 = System.currentTimeMillis();

// Start the new server

if (server instanceof Lifecycle) {

try {

((Lifecycle) server).start();

} catch (LifecycleException e) {

log.error("Catalina.start: ", e);

}

}

long t2 = System.currentTimeMillis();

log.info("Server startup in " + (t2 - t1) + " ms");

try {

// Register shutdown hook

if (useShutdownHook) {

if (shutdownHook == null) {

shutdownHook = new CatalinaShutdownHook();

}

Runtime.getRuntime().addShutdownHook(shutdownHook);

}

} catch (Throwable t) {

// This will fail on JDK 1.2. Ignoring, as Tomcat can run

// fine without the shutdown hook.

}

if (await) {

await();

stop();

}

}

if (shutdownHook == null) {

shutdownHook = new CatalinaShutdownHook();

}

protected class CatalinaShutdownHook extends Thread {

public void run() {

if (server != null) {

Catalina.this.stop();

}

}

}

private static org.apache.commons.logging.Log log=

org.apache.commons.logging.LogFactory.getLog( Catalina.class );

}

public static Log getLog(Class clazz)

throws LogConfigurationException {

return (getFactory().getInstance(clazz));

}

public static LogFactory getFactory() throws LogConfigurationException {

ClassLoader contextClassLoader =

(ClassLoader)AccessController.doPrivileged(

new PrivilegedAction() {

public Object run() {

return getContextClassLoader();

}

});

LogFactory factory = getCachedFactory(contextClassLoader);

if (factory != null)

return factory;

Properties props=null;

try {

InputStream stream = getResourceAsStream(contextClassLoader,

FACTORY_PROPERTIES);

if (stream != null) {

props = new Properties();

props.load(stream);

stream.close();

}

} catch (IOException e) {

} catch (SecurityException e) {

}

try {

String factoryClass = System.getProperty(FACTORY_PROPERTY);

if (factoryClass != null) {

factory = newFactory(factoryClass, contextClassLoader);

}

} catch (SecurityException e) {

;

}

if (factory == null) {

try {

InputStream is = getResourceAsStream(contextClassLoader,

SERVICE_ID);

if( is != null ) {

BufferedReader rd;

try {

rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));

} catch (java.io.UnsupportedEncodingException e) {

rd = new BufferedReader(new InputStreamReader(is));

}

String factoryClassName = rd.readLine();

rd.close();

if (factoryClassName != null &&

! "".equals(factoryClassName)) {

factory= newFactory( factoryClassName, contextClassLoader );

}

}

} catch( Exception ex ) {

;

}

}

if (factory == null && props != null) {

String factoryClass = props.getProperty(FACTORY_PROPERTY);

if (factoryClass != null) {

factory = newFactory(factoryClass, contextClassLoader);

}

}

if (factory == null) {

factory = newFactory(FACTORY_DEFAULT, LogFactory.class.getClassLoader());

}

if (factory != null) {

cacheFactory(contextClassLoader, factory);

if( props!=null ) {

Enumeration names = props.propertyNames();

while (names.hasMoreElements()) {

String name = (String) names.nextElement();

String value = props.getProperty(name);

factory.setAttribute(name, value);

}

}

}

return factory;

}

LogFactory factory = getCachedFactory(contextClassLoader);

private static LogFactory getCachedFactory(ClassLoader contextClassLoader)

{

LogFactory factory = null;

if (contextClassLoader != null)

factory = (LogFactory) factories.get(contextClassLoader);

return factory;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航