1 7 8 package com.sun.jmx.trace; 9 10 import java.util.Properties ; 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.io.IOException ; 16 17 23 public final class Trace implements TraceTags { 24 25 private static TraceDestination out = initDestination(); 26 29 private Trace() { 31 32 } 33 34 private static TraceDestination initDestination() 41 { 42 try 45 { 46 Class.forName("java.util.logging.LogManager"); 47 48 return new TraceManager(); 52 } 53 catch (ClassNotFoundException e) 54 { 55 return null; 58 } 59 } 60 61 65 68 public static synchronized void setDestination(TraceDestination output) { 69 out = output; 70 } 71 72 82 public static boolean isSelected(int level, int type) { 83 final TraceDestination output = out(); 84 if (output != null) return output.isSelected(level,type); 85 return false; 86 } 87 88 89 101 public static boolean send(int level, 102 int type, 103 String className, 104 String methodName, 105 String info) { 106 107 final TraceDestination output = out(); 108 if (output == null) return false; 109 if (!(output.isSelected(level, type))) return false; 110 return output.send(level,type,className,methodName,info); 111 } 112 113 124 public static boolean send(int level, 125 int type, 126 String className, 127 String methodName, 128 Throwable exception) { 129 final TraceDestination output = out(); 130 if (output == null) return false; 131 if (!(output.isSelected(level, type))) return false; 132 return output.send(level,type,className,methodName,exception); 133 } 134 135 143 public static void warning(String loggerName, String msg) { 144 final TraceDestination output = out(); 145 if (output instanceof TraceManager) 146 ((TraceManager)output).warning(loggerName,msg); 148 else if (output != null) 149 output.send(LEVEL_TRACE,INFO_MISC,null,null,msg); 151 } 152 153 161 public static void fine(String loggerName, String msg) { 162 final TraceDestination output = out(); 163 if (output instanceof TraceManager) 164 ((TraceManager)output).fine(loggerName,msg); 166 else if (output != null) 167 output.send(LEVEL_TRACE,INFO_MISC,null,null,msg); 169 } 170 171 174 private static synchronized TraceDestination out() { 175 return out; 176 } 177 178 } 179 | Popular Tags |