1 17 18 package org.apache.geronimo.kernel.log; 19 20 import java.util.logging.ConsoleHandler ; 21 import java.util.logging.Handler ; 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 25 import org.apache.commons.logging.Log; 26 27 32 public class BootstrapJdk14Log implements Log { 33 static { 34 if (GeronimoLogging.isBootstrapLoggingInitializationEnabled()) { 35 Logger root = Logger.getLogger(""); 36 37 GeronimoLogging geronimoLevel = GeronimoLogging.getDefaultLevel(); 38 Level javaLevel; 39 if (geronimoLevel == GeronimoLogging.TRACE) { 40 javaLevel = Level.FINEST; 41 } else if (geronimoLevel == GeronimoLogging.DEBUG) { 42 javaLevel = Level.FINE; 43 } else if (geronimoLevel == GeronimoLogging.INFO) { 44 javaLevel = Level.INFO; 45 } else if (geronimoLevel == GeronimoLogging.WARN) { 46 javaLevel = Level.WARNING; 47 } else { 48 javaLevel = Level.SEVERE; 49 } 50 51 root.setLevel(javaLevel); 53 54 Handler [] handlers = root.getHandlers(); 56 for (int index = 0; index < handlers.length; index++) { 57 if (handlers[index] instanceof ConsoleHandler ) { 58 handlers[index].setLevel(javaLevel); 59 } 60 } 61 } 62 } 63 64 private Logger logger = null; 65 66 public BootstrapJdk14Log(String name) { 67 logger = Logger.getLogger(name); 68 } 69 70 private void log(Level level, String messge, Throwable throwable) { 71 if (logger.isLoggable(level)) { 72 StackTraceElement locations[] = new Throwable ().getStackTrace(); 74 75 String cname = "unknown"; 77 String method = "unknown"; 78 if (locations != null && locations.length > 3) { 79 StackTraceElement caller = locations[3]; 80 cname = caller.getClassName(); 81 method = caller.getMethodName(); 82 } 83 if (throwable == null) { 84 logger.logp(level, cname, method, messge); 85 } else { 86 logger.logp(level, cname, method, messge, throwable); 87 } 88 } 89 } 90 91 public void debug(Object message) { 92 log(Level.FINE, String.valueOf(message), null); 93 } 94 95 public void debug(Object message, Throwable exception) { 96 log(Level.FINE, String.valueOf(message), exception); 97 } 98 99 public void error(Object message) { 100 log(Level.SEVERE, String.valueOf(message), null); 101 } 102 103 public void error(Object message, Throwable exception) { 104 log(Level.SEVERE, String.valueOf(message), exception); 105 } 106 107 public void fatal(Object message) { 108 log(Level.SEVERE, String.valueOf(message), null); 109 } 110 111 public void fatal(Object message, Throwable exception) { 112 log(Level.SEVERE, String.valueOf(message), exception); 113 } 114 115 public Logger getLogger() { 116 return this.logger; 117 } 118 119 public void info(Object message) { 120 log(Level.INFO, String.valueOf(message), null); 121 } 122 123 public void info(Object message, Throwable exception) { 124 log(Level.INFO, String.valueOf(message), exception); 125 } 126 127 public boolean isDebugEnabled() { 128 return (logger.isLoggable(Level.FINE)); 129 } 130 131 public boolean isErrorEnabled() { 132 return (logger.isLoggable(Level.SEVERE)); 133 } 134 135 public boolean isFatalEnabled() { 136 return (logger.isLoggable(Level.SEVERE)); 137 } 138 139 public boolean isInfoEnabled() { 140 return (logger.isLoggable(Level.INFO)); 141 } 142 143 public boolean isTraceEnabled() { 144 return (logger.isLoggable(Level.FINEST)); 145 } 146 147 public boolean isWarnEnabled() { 148 return (logger.isLoggable(Level.WARNING)); 149 } 150 151 public void trace(Object message) { 152 log(Level.FINEST, String.valueOf(message), null); 153 } 154 155 public void trace(Object message, Throwable exception) { 156 log(Level.FINEST, String.valueOf(message), exception); 157 } 158 159 public void warn(Object message) { 160 log(Level.WARNING, String.valueOf(message), null); 161 } 162 163 public void warn(Object message, Throwable exception) { 164 log(Level.WARNING, String.valueOf(message), exception); 165 } 166 } 167 | Popular Tags |