1 2 3 27 package org.apache.tomcat.util.log; 28 29 import java.io.*; 30 import java.lang.reflect.*; 31 import java.util.*; 32 33 34 74 public class Log implements com.sun.org.apache.commons.logging.Log { 75 76 79 public static final int FATAL = Integer.MIN_VALUE; 80 public static final int ERROR = 1; 81 public static final int WARNING = 2; 82 public static final int INFORMATION = 3; 83 public static final int DEBUG = 4; 84 85 86 protected String logname; 89 90 protected String prefix; 93 94 98 private LogHandler proxy; 100 private static LogManager logManager=new LogManager(); 103 104 105 107 protected Log(String channel, String prefix, LogHandler proxy, Object owner) { 108 this.logname=channel; 109 this.prefix=prefix; 110 this.proxy=proxy; 111 } 112 113 117 public static Log getLog( String channel, String prefix ) { 118 return logManager.getLog( channel, prefix, null ); 119 } 120 121 125 public static Log getLog( String channel, Object owner ) { 126 return logManager.getLog( channel, null, owner ); 127 } 128 129 131 134 public void log(String msg) 135 { 136 log(msg, null, INFORMATION); 137 } 138 139 143 public void log(String msg, Throwable t) 144 { 145 log(msg, t, ERROR); 146 } 147 148 151 public void log(String msg, int level) 152 { 153 log(msg, null, level); 154 } 155 156 161 public void log(String msg, Throwable t, int level) 162 { 163 log( prefix, msg, t, level ); 164 } 165 166 168 public void log( String prefix, String msg, Throwable t, int level ) { 169 proxy.log( prefix, msg, t, level ); 170 } 171 172 175 public void flush() { 176 proxy.flush(); 177 } 178 179 public void close() { 180 proxy.close(); 181 } 182 183 185 public int getLevel() { 186 return proxy.getLevel(); 187 } 188 189 191 194 202 public static LogManager setLogManager( LogManager lm ) { 203 if( logManager.getClass() == LogManager.class ) { 206 LogManager oldLM=logManager; 207 logManager=lm; 208 return oldLM; 209 } 210 return null; 211 } 212 213 public String getChannel( LogManager lm ) { 214 if( lm != logManager ) return null; 215 return logname; 216 } 217 218 public void setProxy( LogManager lm, LogHandler l ) { 219 if( lm!= logManager ) { 221 log("Attempt to change proxy " + lm + " " + logManager); 222 return; 223 } 224 proxy=l; 225 } 226 227 228 230 231 233 public void debug(Object message) { 234 log(message.toString(), null, DEBUG); 235 } 236 237 public void debug(Object message, Throwable exception) { 238 log(message.toString(), exception, DEBUG); 239 } 240 241 public void error(Object message) { 242 log(message.toString(), null, ERROR); 243 } 244 245 public void error(Object message, Throwable exception) { 246 log(message.toString(), exception, ERROR); 247 } 248 249 public void fatal(Object message) { 250 log(message.toString(), null, FATAL); 251 } 252 253 public void fatal(Object message, Throwable exception) { 254 log(message.toString(), exception, FATAL); 255 } 256 257 public void info(Object message) { 258 log(message.toString(), null, INFORMATION); 259 } 260 261 public void info(Object message, Throwable exception) { 262 log(message.toString(), exception, INFORMATION); 263 } 264 public void trace(Object message) { 265 log(message.toString(), null, DEBUG); 266 } 267 public void trace(Object message, Throwable exception) { 268 log(message.toString(), exception, DEBUG); 269 } 270 public void warn(Object message) { 271 log(message.toString(), null, WARNING); 272 } 273 public void warn(Object message, Throwable exception) { 274 log(message.toString(), exception, WARNING); 275 } 276 277 public boolean isDebugEnabled() { 278 return proxy.getLevel() <= DEBUG; 279 } 280 public boolean isErrorEnabled() { 281 return proxy.getLevel() <= ERROR; 282 } 283 public boolean isFatalEnabled() { 284 return proxy.getLevel() <= FATAL; 285 } 286 public boolean isInfoEnabled() { 287 return proxy.getLevel() <= INFORMATION; 288 } 289 public boolean isTraceEnabled() { 290 return proxy.getLevel() <= DEBUG; 291 } 292 public boolean isWarnEnabled() { 293 return proxy.getLevel() <= WARNING; 294 } 295 296 324 325 326 } 327 | Popular Tags |