1 package com.ibatis.common.logging; 2 3 import java.lang.reflect.Constructor ; 4 5 public class LogFactory { 6 7 private static Constructor 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 testClassName, String implClassName) { 17 if (logConstructor == null) { 18 try { 19 Class.forName(testClassName); 20 Class implClass = Class.forName(implClassName); 21 logConstructor = implClass.getConstructor(new Class []{Class .class}); 22 } catch (Throwable t) { 23 } 24 } 25 } 26 27 public static Log getLog(Class aClass) { 28 try { 29 return (Log)logConstructor.newInstance(new Object []{aClass}); 30 } catch (Throwable t) { 31 throw new RuntimeException ("Error creating logger for class " + aClass + ". Cause: " + t, t); 32 } 33 } 34 35 } 36 | Popular Tags |