1 9 10 package org.mmbase.util.logging; 11 import java.util.*; 12 import org.apache.log4j.spi.LocationInfo; 13 14 30 31 public class ExceptionImpl extends AbstractSimpleImpl implements Logger { 32 33 private String cat; 34 private static Map instances = new HashMap(); 35 protected static int exceptionLevel = Level.WARN_INT; 36 protected static Level staticLevel = Level.WARN; 37 38 private ExceptionImpl(String c) { 39 cat = c; 40 } 41 42 public static ExceptionImpl getLoggerInstance(String name) { 43 if (instances.containsKey(name)) { 44 return (ExceptionImpl) instances.get(name); 45 } else { 46 ExceptionImpl i = new ExceptionImpl(name); 47 i.setLevel(staticLevel); 48 instances.put(name, i); 49 return i; 50 } 51 } 52 53 59 public static void configure(String c) { 60 if (c == null) { 61 return; } else { 63 StringTokenizer t = new StringTokenizer(c, ","); 64 if (t.hasMoreTokens()) { 65 exceptionLevel = Level.toLevel(t.nextToken()).toInt(); 66 } 67 if (t.hasMoreTokens()) { 68 Level l = Level.toLevel(t.nextToken()); 69 staticLevel = l; 70 Iterator i = instances.values().iterator(); 71 while (i.hasNext()) { 72 Logger log = (Logger) i.next(); 73 log.setLevel(l); 74 } 75 } 76 } 77 } 78 79 protected final void log (String s, Level l) { 80 if (l.toInt() >= level) { 81 Throwable t = new Throwable (); 82 LocationInfo info = new LocationInfo(t, AbstractSimpleImpl.class.getName()); 83 System.out.println(info.getFileName() + ":" + info.getMethodName() + "." + info.getLineNumber() + ": " + s); 84 System.out.println(Logging.stackTrace(t)); 85 } 86 if (l.toInt() >= exceptionLevel) { 87 throw new LoggingException(cat + ":" + s, l); 88 } 89 } 90 91 92 } 93 | Popular Tags |