1 22 39 40 package org.objectweb.petals.util.monolog.wrapper.javalog; 41 42 import java.util.Enumeration ; 43 44 import org.objectweb.util.monolog.api.BasicLevel; 45 import org.objectweb.util.monolog.api.Handler; 46 import org.objectweb.util.monolog.api.Level; 47 import org.objectweb.util.monolog.wrapper.common.AbstractFactory; 48 import org.objectweb.util.monolog.wrapper.javaLog.LevelImpl; 49 50 57 public class Logger extends java.util.logging.Logger implements 58 org.objectweb.util.monolog.api.TopicalLogger { 59 60 63 protected java.util.logging.Logger inner = null; 64 65 68 boolean enabled = true; 69 70 76 protected Logger(java.util.logging.Logger inner) { 77 super(inner.getName(), inner.getResourceBundleName()); 78 this.inner = inner; 79 } 80 81 89 protected Logger(String name, String resName) { 90 super(name, resName); 91 this.inner = this; 92 } 93 94 97 105 public void addHandler(Handler h) throws Exception { 106 if (inner == this) { 107 super.addHandler((GenericHandler) h); 108 if (AbstractFactory.debug) { 109 AbstractFactory.debug("logger(" + getName() + ").addHandler: " 110 + h.getName() + "=>" + super.getHandlers().length); 111 } 112 } else { 113 inner.addHandler((GenericHandler) h); 114 if (AbstractFactory.debug) { 115 AbstractFactory.debug("logger(" + getName() + ").addHandler: " 116 + h.getName() + "=>" + inner.getHandlers().length); 117 } 118 } 119 } 120 121 124 public void addHandler(java.util.logging.Handler handler) { 125 GenericHandler gh = null; 126 if (handler instanceof GenericHandler) { 127 gh = (GenericHandler) handler; 128 } else { 129 gh = new GenericHandler(handler.toString(), handler); 130 } 131 if (inner == this) { 132 super.addHandler(gh); 133 } else { 134 inner.addHandler(gh); 135 } 136 } 137 138 145 public void addTopic(String topic) throws Exception { 146 } 147 148 151 public boolean getAdditivity() { 152 return inner.getUseParentHandlers(); 153 } 154 155 161 public Object getAttribute(String name) { 162 return null; 163 } 164 165 168 public String [] getAttributeNames() { 169 return new String [0]; 170 } 171 172 public int getCurrentIntLevel() { 173 java.util.logging.Level l = getLevel(); 174 return (l == null ? BasicLevel.INHERIT : l.intValue()); 175 } 176 177 public Level getCurrentLevel() { 178 return LevelImpl.getLevel(getCurrentIntLevel()); 179 } 180 181 187 public synchronized Handler[] getHandler() { 188 Object [] os; 189 if (inner == this) { 190 os = super.getHandlers(); 191 } else { 192 os = inner.getHandlers(); 193 } 194 Handler[] hs = new Handler[os.length]; 195 for (int i = 0; i < os.length; i++) { 196 if (os[i] instanceof Handler) { 197 hs[i] = (Handler) os[i]; 198 } else { 199 hs[i] = new GenericHandler("", 200 (java.util.logging.Handler ) os[i]); 201 } 202 } 203 return hs; 204 } 205 206 213 public Handler getHandler(String hn) { 214 Object [] hs; 215 if (inner == this) { 216 hs = super.getHandlers(); 217 } else { 218 hs = inner.getHandlers(); 219 } 220 for (int i = 0; i < hs.length; i++) { 221 if (hs[i] instanceof Handler 222 && hn.equals(((Handler) hs[i]).getName())) { 223 return (Handler) hs[i]; 224 } 225 } 226 return null; 227 } 228 229 232 public String [] getTopic() { 233 return new String [] {AbstractFactory.getTopicWithoutPrefix(inner 234 .getName())}; 235 } 236 237 241 public Enumeration getTopics() { 242 return null; 243 } 244 245 248 public String getType() { 249 return "logger"; 250 } 251 252 public boolean isLoggable(int l) { 253 return enabled && super.isLoggable(LevelImpl.int2Level(l)); 254 } 255 256 public boolean isLoggable(org.objectweb.util.monolog.api.Level l) { 257 return enabled && super.isLoggable(LevelImpl.convertLevel(l)); 258 } 259 260 public boolean isOn() { 261 return enabled; 262 } 263 264 public void log(int l, Object o) { 265 inner.log(LevelImpl.int2Level(l), (o == null ? "null" : o.toString())); 266 } 267 268 271 public void log(int level, Object o, Object location, Object method) { 272 inner.logp(LevelImpl.int2Level(level), (location == null ? "null" 273 : location.toString()), (method == null ? "null" : method 274 .toString()), (o == null ? "null" : o.toString())); 275 } 276 277 public void log(int l, Object o, Throwable t) { 278 inner.log(LevelImpl.int2Level(l), (o == null ? "null" : o.toString()), 279 t); 280 } 281 282 public void log(int level, Object o, Throwable t, Object location, 283 Object method) { 284 inner.logp(LevelImpl.int2Level(level), (location == null ? "null" 285 : location.toString()), (method == null ? "null" : method 286 .toString()), (o == null ? "null" : o.toString()), t); 287 } 288 289 public void log(Level l, Object o) { 290 inner.log(LevelImpl.convertLevel(l), 291 (o == null ? "null" : o.toString())); 292 } 293 294 public void log(Level l, Object o, Object location, Object method) { 295 inner.logp(LevelImpl.convertLevel(l), (location == null ? "null" 296 : location.toString()), (method == null ? "null" : method 297 .toString()), (o == null ? "null" : o.toString())); 298 } 299 300 public void log(Level l, Object o, Throwable t) { 301 inner.log(LevelImpl.convertLevel(l), 302 (o == null ? "null" : o.toString()), t); 303 } 304 305 public void log(Level l, Object o, Throwable t, Object location, 306 Object method) { 307 inner.logp(LevelImpl.convertLevel(l), (location == null ? "null" 308 : location.toString()), (method == null ? "null" : method 309 .toString()), (o == null ? "null" : o.toString()), t); 310 } 311 312 316 public void removeAllHandlers() throws Exception { 317 java.util.logging.Handler [] hs = inner.getHandlers(); 318 if (AbstractFactory.debug) { 319 AbstractFactory.debug("logger(" + getName() 320 + ").removeAllHandlers(): before: " + hs.length); 321 } 322 for (int i = 0; i < hs.length; i++) { 323 if (inner == this) { 324 super.removeHandler(hs[i]); 325 } else { 326 inner.removeHandler(hs[i]); 327 328 } 329 } 330 if (AbstractFactory.debug) { 331 AbstractFactory.debug("logger(" + getName() 332 + ").removeAllHandlers(): before: " 333 + inner.getHandlers().length); 334 } 335 } 336 337 341 public void removeHandler(Handler h) throws Exception { 342 if (inner == this) { 343 super.removeHandler((GenericHandler) h); 344 } else { 345 inner.removeHandler((GenericHandler) h); 346 } 347 } 348 349 356 public void removeTopic(String topic) throws Exception { 357 } 358 359 362 public void setAdditivity(boolean a) { 363 inner.setUseParentHandlers(a); 364 } 365 366 375 public Object setAttribute(String name, Object value) { 376 return null; 377 } 378 379 public void setIntLevel(int level) { 380 inner.setLevel(LevelImpl.int2Level(level)); 381 } 382 383 public void setLevel(org.objectweb.util.monolog.api.Level l) { 384 inner.setLevel(LevelImpl.convertLevel(l)); 385 } 386 387 390 public void setName(String name) { 391 } 392 393 public void turnOff() { 394 enabled = false; 395 } 396 397 public void turnOn() { 398 enabled = true; 399 } 400 } 401 | Popular Tags |