1 7 package com.sun.jmx.trace; 8 9 import java.io.IOException ; 10 11 import java.util.logging.Level ; 12 import java.util.logging.Logger ; 13 14 111 public class TraceManager implements TraceDestination { 112 113 126 private static Level getLevel(int level) 127 { 128 switch(level) 129 { 130 case TraceTags.LEVEL_DEBUG: 131 return Level.FINEST; 132 case TraceTags.LEVEL_TRACE: 133 return Level.FINER; 134 case TraceTags.LEVEL_ERROR: 135 return Level.SEVERE; 136 default: 137 return null; 138 } 139 } 140 141 161 private static Logger getLogger(int type) 162 { 163 switch(type) 164 { 165 case TraceTags.INFO_MBEANSERVER: 166 return Logger.getLogger("javax.management.mbeanserver"); 167 case TraceTags.INFO_ADAPTOR_SNMP: 168 return Logger.getLogger("com.sun.jmx.snmp.daemon"); 169 case TraceTags.INFO_SNMP: 170 return Logger.getLogger("com.sun.jmx.snmp"); 171 case TraceTags.INFO_MLET: 172 return Logger.getLogger("javax.management.mlet"); 173 case TraceTags.INFO_MONITOR: 174 return Logger.getLogger("javax.management.monitor"); 175 case TraceTags.INFO_TIMER: 176 return Logger.getLogger("javax.management.timer"); 177 case TraceTags.INFO_MISC: 178 return Logger.getLogger("javax.management.misc"); 179 case TraceTags.INFO_NOTIFICATION: 180 return Logger.getLogger("javax.management.notification"); 181 case TraceTags.INFO_RELATION: 182 return Logger.getLogger("javax.management.relation"); 183 case TraceTags.INFO_MODELMBEAN: 184 return Logger.getLogger("javax.management.modelmbean"); 185 default: 186 return null; 187 } 188 } 189 190 193 public boolean isSelected(int level, int type) 194 { 195 Logger logger; 196 Level lvl; 197 if (((logger = getLogger(type)) != null) && 198 ((lvl = getLevel(level)) != null)) 199 { 200 return logger.isLoggable(lvl); 201 } 202 return false; 203 } 204 205 211 public boolean send(int level, 212 int type, 213 String className, 214 String methodName, 215 String info) 216 { 217 if (isSelected(level, type)) 218 { 219 getLogger(type).logp(getLevel(level), className, methodName, info); 220 return true; 221 } 222 return false; 223 } 224 225 231 public boolean send(int level, 232 int type, 233 String className, 234 String methodName, 235 Throwable exception) 236 { 237 if (isSelected(level, type)) { 238 getLogger(type).log(getLevel(level), 239 className + ": Exception occured in " + methodName , 240 exception); 241 return true; 242 } 243 return false; 244 } 245 246 251 public void reset() throws IOException 252 { 253 254 } 255 256 263 void warning(String loggerName, String msg) { 264 Logger.getLogger(loggerName).warning(msg); 265 } 266 267 274 void fine(String loggerName, String msg) { 275 Logger.getLogger(loggerName).fine(msg); 276 } 277 278 } 279 280 | Popular Tags |