1 package org.objectweb.petals.util; 2 3 import org.objectweb.util.monolog.api.BasicLevel; 4 import org.objectweb.util.monolog.api.Logger; 5 6 14 public class LoggingUtil { 15 16 private Logger logger; 17 18 public LoggingUtil(Logger logger) { 19 this.logger = logger; 20 } 21 22 private LoggingUtil() { 23 } 24 25 30 public static void call(Logger log) { 31 if (log != null && log.isOn()) { 32 log.log(BasicLevel.LEVEL_DEBUG, "[CALL ] " + classAndMethod()); 33 } 34 } 35 36 42 public static void call(Logger log, Object msg) { 43 if (log != null && log.isOn()) { 44 log.log(BasicLevel.LEVEL_DEBUG, "[CALL ] " + classAndMethod() + " " 45 + msg); 46 } 47 } 48 49 55 public static void debug(Logger log, Object message) { 56 if (log != null && log.isOn()) { 57 log.log(BasicLevel.LEVEL_DEBUG, classAndMethod() + " " + message); 58 } 59 } 60 61 66 public static void end(Logger log) { 67 if (log != null && log.isOn()) { 68 log.log(BasicLevel.LEVEL_DEBUG, "[ END ] " + classAndMethod()); 69 } 70 } 71 72 78 public static void end(Logger log, Object msg) { 79 if (log != null && log.isOn()) { 80 log.log(BasicLevel.LEVEL_DEBUG, "[ END ] " + classAndMethod() + " " 81 + msg); 82 } 83 } 84 85 91 public static void error(Logger log, Object message) { 92 if (log != null && log.isOn()) { 93 log.log(BasicLevel.LEVEL_ERROR, message); 94 } 95 } 96 97 104 public static void error(Logger log, Object message, Throwable throwable) { 105 if (log != null && log.isOn()) { 106 log.log(BasicLevel.LEVEL_ERROR, message, throwable); 107 } 108 } 109 110 116 public static void info(Logger log, Object message) { 117 if (log != null && log.isOn()) { 118 log.log(BasicLevel.LEVEL_INFO, classAndMethod() + " " + message); 119 } 120 } 121 122 129 public static void info(Logger log, Object message, Throwable error) { 130 if (log != null && log.isOn()) { 131 log.log(BasicLevel.LEVEL_INFO, classAndMethod() + " " + message, 132 error); 133 } 134 } 135 136 141 public static void start(Logger log) { 142 if (log != null && log.isOn()) { 143 log.log(BasicLevel.LEVEL_DEBUG, "[START] " + classAndMethod()); 144 } 145 } 146 147 153 public static void start(Logger log, Object msg) { 154 if (log != null && log.isOn()) { 155 log.log(BasicLevel.LEVEL_DEBUG, "[START] " + classAndMethod() + " " 156 + msg); 157 } 158 } 159 160 166 public static void warning(Logger log, Object message) { 167 if (log != null && log.isOn()) { 168 log.log(BasicLevel.LEVEL_WARN, message); 169 } 170 } 171 172 179 public static void warning(Logger log, Object message, Throwable throwable) { 180 if (log != null && log.isOn()) { 181 log.log(BasicLevel.LEVEL_WARN, message, throwable); 182 } 183 } 184 185 189 195 private static String classAndMethod() { 196 String result = null; 197 198 201 Throwable t = new Throwable ().fillInStackTrace(); 202 203 StackTraceElement [] ste = t.getStackTrace(); 204 205 if (ste != null && ste.length > 2) { 206 StackTraceElement element = ste[2]; 207 208 if (element.getClassName().endsWith(LoggingUtil.class.getName())) { 210 element = ste[3]; 211 } 212 String className = element.getClassName(); 213 214 int index = className.lastIndexOf("."); 216 217 if (index > -1) { 218 className = className.substring(index + 1, className.length()); 219 } 220 221 result = className + "." + element.getMethodName() + "()"; 222 } 223 return result; 224 } 225 226 229 public void call() { 230 call(logger); 231 } 232 233 238 public void call(Object msg) { 239 call(logger, msg); 240 } 241 242 247 public void debug(Object message) { 248 debug(logger, message); 249 } 250 251 254 public void end() { 255 end(logger); 256 } 257 258 263 public void end(Object msg) { 264 end(logger, msg); 265 } 266 267 272 public void error(Object message) { 273 error(logger, message); 274 } 275 276 282 public void error(Object message, Throwable throwable) { 283 error(logger, message, throwable); 284 } 285 286 public String getName() { 287 return this.logger.getName(); 288 } 289 290 295 public void info(Object message) { 296 info(logger, message); 297 } 298 299 305 public void info(Object message, Throwable error) { 306 info(logger, message, error); 307 } 308 309 312 public void start() { 313 start(logger); 314 } 315 316 321 public void start(Object msg) { 322 start(logger, msg); 323 } 324 325 330 public void warning(Object message) { 331 warning(logger, message); 332 } 333 334 340 public void warning(Object message, Throwable throwable) { 341 warning(logger, message, throwable); 342 } 343 } 344 | Popular Tags |