1 7 8 package com.sun.jmx.remote.util; 9 10 import java.util.logging.Logger ; 11 12 public class ClassLogger { 13 14 private static final boolean ok; 15 private final String className; 16 private final Logger logger; 17 18 static { 19 24 boolean loaded = false; 25 try { 26 Class c = java.util.logging.Logger .class; 27 loaded = true; 28 } catch (Error e) { 29 } 32 ok = loaded; 33 } 34 35 public ClassLogger(String subsystem, String className) { 36 if (ok) 37 logger = Logger.getLogger(subsystem); 38 else 39 logger = null; 40 this.className = className; 41 } 42 43 public final boolean traceOn() { 44 return finerOn(); 45 } 46 47 public final boolean debugOn() { 48 return finestOn(); 49 } 50 51 public final boolean warningOn() { 52 return ok && logger.isLoggable(java.util.logging.Level.WARNING); 53 } 54 55 public final boolean infoOn() { 56 return ok && logger.isLoggable(java.util.logging.Level.INFO); 57 } 58 59 public final boolean configOn() { 60 return ok && logger.isLoggable(java.util.logging.Level.CONFIG); 61 } 62 63 public final boolean fineOn() { 64 return ok && logger.isLoggable(java.util.logging.Level.FINE); 65 } 66 67 public final boolean finerOn() { 68 return ok && logger.isLoggable(java.util.logging.Level.FINER); 69 } 70 71 public final boolean finestOn() { 72 return ok && logger.isLoggable(java.util.logging.Level.FINEST); 73 } 74 75 public final void debug(String func, String msg) { 76 finest(func,msg); 77 } 78 79 public final void debug(String func, Throwable t) { 80 finest(func,t); 81 } 82 83 public final void debug(String func, String msg, Throwable t) { 84 finest(func,msg,t); 85 } 86 87 public final void trace(String func, String msg) { 88 finer(func,msg); 89 } 90 91 public final void trace(String func, Throwable t) { 92 finer(func,t); 93 } 94 95 public final void trace(String func, String msg, Throwable t) { 96 finer(func,msg,t); 97 } 98 99 public final void error(String func, String msg) { 100 severe(func,msg); 101 } 102 103 public final void error(String func, Throwable t) { 104 severe(func,t); 105 } 106 107 public final void error(String func, String msg, Throwable t) { 108 severe(func,msg,t); 109 } 110 111 public final void finest(String func, String msg) { 112 if (ok) 113 logger.logp(java.util.logging.Level.FINEST, className, func, msg); 114 } 115 116 public final void finest(String func, Throwable t) { 117 if (ok) 118 logger.logp(java.util.logging.Level.FINEST, className, func, 119 t.toString(), t); 120 } 121 122 public final void finest(String func, String msg, Throwable t) { 123 if (ok) 124 logger.logp(java.util.logging.Level.FINEST, className, func, msg, 125 t); 126 } 127 128 public final void finer(String func, String msg) { 129 if (ok) 130 logger.logp(java.util.logging.Level.FINER, className, func, msg); 131 } 132 133 public final void finer(String func, Throwable t) { 134 if (ok) 135 logger.logp(java.util.logging.Level.FINER, className, func, 136 t.toString(), t); 137 } 138 139 public final void finer(String func, String msg, Throwable t) { 140 if (ok) 141 logger.logp(java.util.logging.Level.FINER, className, func, msg,t); 142 } 143 144 public final void fine(String func, String msg) { 145 if (ok) 146 logger.logp(java.util.logging.Level.FINE, className, func, msg); 147 } 148 149 public final void fine(String func, Throwable t) { 150 if (ok) 151 logger.logp(java.util.logging.Level.FINE, className, func, 152 t.toString(), t); 153 } 154 155 public final void fine(String func, String msg, Throwable t) { 156 if (ok) 157 logger.logp(java.util.logging.Level.FINE, className, func, msg, 158 t); 159 } 160 161 public final void config(String func, String msg) { 162 if (ok) 163 logger.logp(java.util.logging.Level.CONFIG, className, func, msg); 164 } 165 166 public final void config(String func, Throwable t) { 167 if (ok) 168 logger.logp(java.util.logging.Level.CONFIG, className, func, 169 t.toString(), t); 170 } 171 172 public final void config(String func, String msg, Throwable t) { 173 if (ok) 174 logger.logp(java.util.logging.Level.CONFIG, className, func, msg, 175 t); 176 } 177 178 public final void info(String func, String msg) { 179 if (ok) 180 logger.logp(java.util.logging.Level.INFO, className, func, msg); 181 } 182 183 public final void info(String func, Throwable t) { 184 if (ok) 185 logger.logp(java.util.logging.Level.INFO, className, func, 186 t.toString(), t); 187 } 188 189 public final void info(String func, String msg, Throwable t) { 190 if (ok) 191 logger.logp(java.util.logging.Level.INFO, className, func, msg, 192 t); 193 } 194 195 public final void warning(String func, String msg) { 196 if (ok) 197 logger.logp(java.util.logging.Level.WARNING, className, func, msg); 198 } 199 200 public final void warning(String func, Throwable t) { 201 if (ok) 202 logger.logp(java.util.logging.Level.WARNING, className, func, 203 t.toString(), t); 204 } 205 206 public final void warning(String func, String msg, Throwable t) { 207 if (ok) 208 logger.logp(java.util.logging.Level.WARNING, className, func, msg, 209 t); 210 } 211 212 public final void severe(String func, String msg) { 213 if (ok) 214 logger.logp(java.util.logging.Level.SEVERE, className, func, msg); 215 } 216 217 public final void severe(String func, Throwable t) { 218 if (ok) 219 logger.logp(java.util.logging.Level.SEVERE, className, func, 220 t.toString(), t); 221 } 222 223 public final void severe(String func, String msg, Throwable t) { 224 if (ok) 225 logger.logp(java.util.logging.Level.SEVERE, className, func, msg, 226 t); 227 } 228 } 229 | Popular Tags |