KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > common > logging > LogFactory


1 package com.ibatis.common.logging;
2
3 import java.lang.reflect.Constructor JavaDoc;
4
5 public class LogFactory {
6
7   private static Constructor JavaDoc logConstructor;
8
9   static {
10     tryImplementation("org.apache.commons.logging.LogFactory", "com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl");
11     tryImplementation("org.apache.log4j.Logger", "com.ibatis.common.logging.log4j.Log4jImpl");
12     tryImplementation("java.util.logging.Logger", "com.ibatis.common.logging.jdk14.Jdk14LoggingImpl");
13     tryImplementation("java.lang.Object", "com.ibatis.common.logging.nologging.NoLoggingImpl");
14   }
15
16   private static void tryImplementation(String JavaDoc testClassName, String JavaDoc implClassName) {
17     if (logConstructor == null) {
18       try {
19         Class.forName(testClassName);
20         Class JavaDoc implClass = Class.forName(implClassName);
21         logConstructor = implClass.getConstructor(new Class JavaDoc[]{Class JavaDoc.class});
22       } catch (Throwable JavaDoc t) {
23       }
24     }
25   }
26
27   public static Log getLog(Class JavaDoc aClass) {
28     try {
29       return (Log)logConstructor.newInstance(new Object JavaDoc[]{aClass});
30     } catch (Throwable JavaDoc t) {
31       throw new RuntimeException JavaDoc("Error creating logger for class " + aClass + ". Cause: " + t, t);
32     }
33   }
34
35 }
36
Popular Tags