1 17 18 package org.apache.geronimo.kernel.log; 19 20 import java.lang.reflect.Method ; 21 import java.util.Map ; 22 import java.util.HashMap ; 23 24 import org.apache.commons.logging.LogFactory; 25 26 29 public class GeronimoLogging { 30 31 private static final Map levels = new HashMap (); 33 34 public static final GeronimoLogging TRACE = new GeronimoLogging("TRACE"); 35 public static final GeronimoLogging DEBUG = new GeronimoLogging("DEBUG"); 36 public static final GeronimoLogging INFO = new GeronimoLogging("INFO"); 37 public static final GeronimoLogging WARN = new GeronimoLogging("WARN"); 38 public static final GeronimoLogging ERROR = new GeronimoLogging("ERROR"); 39 public static final GeronimoLogging FATAL = new GeronimoLogging("FATAL"); 40 41 private static boolean initialized = false; 42 private static GeronimoLogging consoleLogLevel = ERROR; 43 private static GeronimoLogging defaultLevel; 44 45 51 public static void initialize(GeronimoLogging level) { 52 if (!initialized) { 53 defaultLevel = level; 54 consoleLogLevel = level; 55 56 LogFactory.getLog(GeronimoLogging.class); 58 59 try { 63 Class clazz = Class.forName("mx4j.log.Log"); 64 Class paramClazz = Class.forName("mx4j.log.Logger"); 65 Method method = clazz.getDeclaredMethod("redirectTo", new Class [] {paramClazz}); 66 paramClazz = Class.forName("mx4j.log.CommonsLogger"); 67 method.invoke(null, new Object [] {paramClazz.newInstance()}); 68 } catch (ClassNotFoundException e) { 69 } catch (Exception e) { 71 throw (AssertionError ) new AssertionError ("Cannot force MX4J to use commons logging.").initCause(e); 72 } 73 74 initialized = true; 75 } 76 } 77 78 public static void setDefaultLogLevel(GeronimoLogging level) { 79 defaultLevel = level; 80 } 81 82 public static GeronimoLogging getDefaultLevel() { 83 return defaultLevel; 84 } 85 86 public static GeronimoLogging getConsoleLogLevel() { 87 return consoleLogLevel; 88 } 89 90 public static void setConsoleLogLevel(GeronimoLogging consoleLogLevel) { 91 GeronimoLogging.consoleLogLevel = consoleLogLevel; 92 } 93 94 public static GeronimoLogging getGeronimoLogging(String level) { 95 return (GeronimoLogging) levels.get(level); 96 } 97 98 private final String level; 99 100 private GeronimoLogging(String level) { 101 this.level = level; 102 levels.put(level, this); 103 } 104 105 public String toString() { 106 return level; 107 } 108 109 117 public static boolean isBootstrapLoggingInitializationEnabled() { 118 String value = System.getProperty("geronimo.bootstrap.logging.enabled"); 119 if (value == null) { 120 return true; 121 } 122 else { 123 return Boolean.valueOf(value).booleanValue(); 124 } 125 } 126 } 127 | Popular Tags |