1 18 19 package org.objectweb.util.monolog.wrapper.javaLog; 20 21 import org.objectweb.util.monolog.api.Level; 22 import org.objectweb.util.monolog.api.Handler; 23 import org.objectweb.util.monolog.api.BasicLevel; 24 import org.objectweb.util.monolog.wrapper.common.AbstractFactory; 25 26 import java.util.Enumeration ; 27 28 34 public class Logger 35 extends java.util.logging.Logger 36 implements org.objectweb.util.monolog.api.TopicalLogger { 37 38 41 boolean enabled = true; 42 43 46 protected java.util.logging.Logger inner = null; 47 48 52 protected Logger(java.util.logging.Logger inner) { 53 super(inner.getName(), inner.getResourceBundleName()); 54 this.inner = inner; 55 } 56 57 62 protected Logger(String name, String resName) { 63 super(name, resName); 64 this.inner = this; 65 } 66 67 70 public void addHandler(java.util.logging.Handler handler) { 71 GenericHandler gh = null; 72 if (handler instanceof GenericHandler) { 73 gh = (GenericHandler) handler; 74 } else { 75 gh = new GenericHandler(handler.toString(), handler); 76 } 77 if (inner == this) { 78 super.addHandler(gh); 79 } else { 80 inner.addHandler(gh); 81 } 82 } 83 84 87 90 public void setName(String name) { 91 } 92 93 96 public String getType() { 97 return "logger"; 98 } 99 100 103 public String [] getAttributeNames() { 104 return new String [0]; 105 } 106 107 111 public Object getAttribute(String name) { 112 return null; 113 } 114 115 121 public Object setAttribute(String name, Object value) { 122 return null; 123 } 124 125 126 133 public void addHandler(Handler h) throws Exception { 134 if (inner == this) { 135 super.addHandler((GenericHandler) h); 136 if (AbstractFactory.debug) { 137 AbstractFactory.debug("logger(" + getName() + ").addHandler: " 138 + h.getName() + "=>" + super.getHandlers().length); 139 } 140 } else { 141 inner.addHandler((GenericHandler) h); 142 if (AbstractFactory.debug) { 143 AbstractFactory.debug("logger(" + getName() + ").addHandler: " 144 + h.getName() + "=>" + inner.getHandlers().length); 145 } 146 } 147 } 148 149 154 public Handler getHandler(String hn) { 155 Object [] hs; 156 if (inner == this) { 157 hs = super.getHandlers(); 158 } else { 159 hs = inner.getHandlers(); 160 } 161 for (int i = 0; i < hs.length; i++) { 162 if (hs[i] instanceof Handler && hn.equals(((Handler) hs[i]).getName())) { 163 return (Handler) hs[i]; 164 } 165 } 166 return null; 167 } 168 169 174 public synchronized Handler[] getHandler() { 175 Object [] os; 176 if (inner == this) { 177 os = super.getHandlers(); 178 } else { 179 os = inner.getHandlers(); 180 } 181 Handler[] hs = new Handler[os.length]; 182 for(int i = 0; i < os.length; i++) { 183 if (os[i] instanceof Handler) { 184 hs[i] = (Handler) os[i]; 185 } else { 186 hs[i] = new GenericHandler("", (java.util.logging.Handler ) os[i]); 187 } 188 } 189 return hs; 190 } 191 192 196 public void removeHandler(Handler h) throws Exception { 197 if (inner == this) { 198 super.removeHandler((GenericHandler) h); 199 } else { 200 inner.removeHandler((GenericHandler) h); 201 } 202 } 203 204 208 public void removeAllHandlers() throws Exception { 209 java.util.logging.Handler [] hs = inner.getHandlers(); 210 if (AbstractFactory.debug) { 211 AbstractFactory.debug("logger(" + getName() 212 + ").removeAllHandlers(): before: " + hs.length); 213 } 214 for (int i = 0; i < hs.length; i++) { 215 if (inner == this) { 216 super.removeHandler(hs[i]); 217 } else { 218 inner.removeHandler(hs[i]); 219 220 } 221 } 222 if (AbstractFactory.debug) { 223 AbstractFactory.debug("logger(" + getName() 224 + ").removeAllHandlers(): before: " 225 + inner.getHandlers().length); 226 } 227 } 228 229 232 public void setAdditivity(boolean a) { 233 inner.setUseParentHandlers(a); 234 } 235 236 239 public boolean getAdditivity() { 240 return inner.getUseParentHandlers(); 241 } 242 243 249 public void addTopic(String topic) throws Exception { 250 } 252 253 256 public String [] getTopic() { 257 return new String [] { AbstractFactory.getTopicWithoutPrefix(inner.getName()) }; 259 } 260 261 265 public Enumeration getTopics() { 266 return null; 268 } 269 270 276 public void removeTopic(String topic) throws Exception { 277 } 279 280 283 public void setIntLevel(int level) { 284 inner.setLevel(LevelImpl.int2Level(level)); 285 } 286 287 public void setLevel(org.objectweb.util.monolog.api.Level l) { 288 inner.setLevel(LevelImpl.convertLevel(l)); 289 } 290 291 public int getCurrentIntLevel() { 292 java.util.logging.Level l = getLevel(); 293 return (l == null ? BasicLevel.INHERIT : l.intValue()); 294 } 295 296 public Level getCurrentLevel() { 297 return LevelImpl.getLevel(getCurrentIntLevel()); 298 } 299 300 public boolean isLoggable(int l) { 301 return enabled && super.isLoggable(LevelImpl.int2Level(l)); 302 } 303 304 public boolean isLoggable(org.objectweb.util.monolog.api.Level l) { 305 return enabled && super.isLoggable(LevelImpl.convertLevel(l)); 306 } 307 308 public boolean isOn() { 309 return enabled; 310 } 311 312 public void log(int l, Object o) { 313 inner.log(LevelImpl.int2Level(l), (o == null ? "null" : o.toString())); 314 } 315 316 public void log(Level l, Object o) { 317 inner.log(LevelImpl.convertLevel(l), (o == null ? "null" : o.toString())); 318 } 319 320 public void log(int l, Object o, Throwable t) { 321 inner.log(LevelImpl.int2Level(l), (o == null ? "null" : o.toString()), t); 322 } 323 324 public void log(Level l, Object o, Throwable t) { 325 inner.log(LevelImpl.convertLevel(l), (o == null ? "null" : o.toString()), t); 326 } 327 328 public void log(int level, Object o, Object location, Object method) { 329 inner.logp(LevelImpl.int2Level(level), 330 (location == null ? "null" : location.toString()), 331 (method == null ? "null" : method.toString()), 332 (o == null ? "null" : o.toString())); 333 } 334 335 public void log(Level l, Object o, Object location, Object method) { 336 inner.logp(LevelImpl.convertLevel(l), 337 (location == null ? "null" : location.toString()), 338 (method == null ? "null" : method.toString()), 339 (o == null ? "null" : o.toString())); 340 } 341 342 public void log(int level, Object o, Throwable t, Object location, 343 Object method) { 344 inner.logp(LevelImpl.int2Level(level), 345 (location == null ? "null" : location.toString()), 346 (method == null ? "null" : method.toString()), 347 (o == null ? "null" : o.toString()), 348 t); 349 } 350 351 public void log(Level l, Object o, Throwable t, Object location, 352 Object method) { 353 inner.logp(LevelImpl.convertLevel(l), 354 (location == null ? "null" : location.toString()), 355 (method == null ? "null" : method.toString()), 356 (o == null ? "null" : o.toString()), 357 t); 358 } 359 360 public void turnOn() { 361 enabled = true; 362 } 363 364 public void turnOff() { 365 enabled = false; 366 } 367 } 368 | Popular Tags |