1 16 package com.google.gwt.core.ext; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 24 public interface TreeLogger { 25 26 29 class Type { 30 31 private static final int TYPES_COUNT = 7; 32 33 39 private static Map labelMap; 40 private static Type[] typeList; 41 42 static { 43 Type type = ERROR; 45 } 46 47 52 public static Type[] instances() { 53 return (Type[]) typeList.clone(); 54 } 55 56 63 public static Type valueOf(String label) { 64 return (Type) labelMap.get(label.toUpperCase()); 65 } 66 67 private final String label; 68 private final boolean needsAttention; 69 private final int priority; 70 71 74 private Type(boolean needsAttention, String name, int priority) { 75 if (labelMap == null) { 76 labelMap = new HashMap (); 77 } 78 if (typeList == null) { 79 typeList = new Type[TYPES_COUNT]; 80 } 81 Object existing = labelMap.put(name.toUpperCase(), this); 82 assert (existing == null); 83 assert (typeList[priority] == null); 84 typeList[priority] = this; 85 this.needsAttention = needsAttention; 86 this.label = name; 87 this.priority = priority; 88 } 89 90 95 public String getLabel() { 96 return label; 97 } 98 99 106 public boolean isLowerPriorityThan(Type other) { 107 return this.priority > other.priority; 108 } 109 110 117 public boolean needsAttention() { 118 return needsAttention; 119 } 120 121 public String toString() { 122 return label; 123 } 124 } 125 126 129 Type ERROR = new Type(true, "ERROR", 0); 130 131 134 Type WARN = new Type(true, "WARN", 1); 135 136 139 Type INFO = new Type(false, "INFO", 2); 140 141 144 Type TRACE = new Type(false, "TRACE", 3); 145 146 149 Type DEBUG = new Type(false, "DEBUG", 4); 150 151 155 Type SPAM = new Type(false, "SPAM", 5); 156 157 160 Type ALL = new Type(false, "ALL", 6); 161 162 166 TreeLogger NULL = new TreeLogger() { 167 public TreeLogger branch(Type type, String msg, Throwable caught) { 168 return this; 169 } 170 171 public boolean isLoggable(Type type) { 172 return false; 173 } 174 175 public void log(Type type, String msg, Throwable caught) { 176 } 178 }; 179 180 211 TreeLogger branch(TreeLogger.Type type, String msg, Throwable caught); 212 213 218 boolean isLoggable(TreeLogger.Type type); 219 220 231 void log(TreeLogger.Type type, String msg, Throwable caught); 232 } 233 | Popular Tags |