1 22 package org.objectweb.petals.component.common.util; 23 24 import java.util.Enumeration ; 25 import java.util.ResourceBundle ; 26 import java.util.logging.Filter ; 27 import java.util.logging.Handler ; 28 import java.util.logging.Level ; 29 import java.util.logging.LogRecord ; 30 import java.util.logging.Logger ; 31 32 37 public class ComponentLogger extends Logger { 38 39 42 protected String componentName; 43 44 47 protected Logger logger; 48 49 public ComponentLogger(Logger logger, String loggerName, 50 String resourceBundleName, String componentName) { 51 super(loggerName, resourceBundleName); 52 this.logger = logger; 53 this.componentName = componentName; 54 } 55 56 public void addHandler(Handler handler) throws SecurityException { 57 logger.addHandler(handler); 58 } 59 60 public void config(String msg) { 61 logger.config(msg); 62 } 63 64 public void entering(String sourceClass, String sourceMethod) { 65 logger.entering(sourceClass, sourceMethod); 66 } 67 68 public void entering(String sourceClass, String sourceMethod, Object param1) { 69 logger.entering(sourceClass, sourceMethod, param1); 70 } 71 72 public void entering(String sourceClass, String sourceMethod, 73 Object [] params) { 74 logger.entering(sourceClass, sourceMethod, params); 75 } 76 77 public boolean equals(Object obj) { 78 return logger.equals(obj); 79 } 80 81 public void exiting(String sourceClass, String sourceMethod) { 82 logger.exiting(sourceClass, sourceMethod); 83 } 84 85 public void exiting(String sourceClass, String sourceMethod, Object result) { 86 logger.exiting(sourceClass, sourceMethod, result); 87 } 88 89 public void fine(String msg) { 90 logger.fine("[" 91 + componentName + "] " + convertMsg(msg)); 92 } 93 94 public void finer(String msg) { 95 logger.finer("[" 96 + componentName + "] " + convertMsg(msg)); 97 } 98 99 public void finest(String msg) { 100 logger.finest("[" 101 + componentName + "] " + convertMsg(msg)); 102 } 103 104 public Filter getFilter() { 105 return logger.getFilter(); 106 } 107 108 public Handler [] getHandlers() { 109 return logger.getHandlers(); 110 } 111 112 public Level getLevel() { 113 return logger.getLevel(); 114 } 115 116 public String getName() { 117 return logger.getName(); 118 } 119 120 public Logger getParent() { 121 return logger.getParent(); 122 } 123 124 public ResourceBundle getResourceBundle() { 125 return logger.getResourceBundle(); 126 } 127 128 public String getResourceBundleName() { 129 return logger.getResourceBundleName(); 130 } 131 132 public boolean getUseParentHandlers() { 133 return logger.getUseParentHandlers(); 134 } 135 136 public int hashCode() { 137 return logger.hashCode(); 138 } 139 140 public void info(String msg) { 141 logger.info("[" 142 + componentName + "] " + convertMsg(msg)); 143 } 144 145 public boolean isLoggable(Level level) { 146 return logger.isLoggable(level); 147 } 148 149 public void log(Level level, String msg) { 150 logger.log(level, "[" 151 + componentName + "] " + convertMsg(msg)); 152 } 153 154 public void log(Level level, String msg, Object param1) { 155 logger.log(level, "[" 156 + componentName + "] " + convertMsg(msg), param1); 157 } 158 159 public void log(Level level, String msg, Object [] params) { 160 logger.log(level, "[" 161 + componentName + "] " + convertMsg(msg), params); 162 } 163 164 public void log(Level level, String msg, Throwable thrown) { 165 logger.log(level, "[" 166 + componentName + "] " + convertMsg(msg), thrown); 167 } 168 169 public void log(LogRecord record) { 170 logger.log(record); 171 } 172 173 public void logp(Level level, String sourceClass, String sourceMethod, 174 String msg) { 175 logger.logp(level, sourceClass, sourceMethod, "[" 176 + componentName + "] " + convertMsg(msg)); 177 } 178 179 public void logp(Level level, String sourceClass, String sourceMethod, 180 String msg, Object param1) { 181 logger.logp(level, sourceClass, sourceMethod, "[" 182 + componentName + "] " + convertMsg(msg), param1); 183 } 184 185 public void logp(Level level, String sourceClass, String sourceMethod, 186 String msg, Object [] params) { 187 logger.logp(level, sourceClass, sourceMethod, "[" 188 + componentName + "] " + convertMsg(msg), params); 189 } 190 191 public void logp(Level level, String sourceClass, String sourceMethod, 192 String msg, Throwable thrown) { 193 logger.logp(level, sourceClass, sourceMethod, "[" 194 + componentName + "] " + convertMsg(msg), thrown); 195 } 196 197 public void logrb(Level level, String sourceClass, String sourceMethod, 198 String bundleName, String msg) { 199 logger.logrb(level, sourceClass, sourceMethod, bundleName, "[" 200 + componentName + "] " + convertMsg(msg)); 201 } 202 203 public void logrb(Level level, String sourceClass, String sourceMethod, 204 String bundleName, String msg, Object param1) { 205 logger.logrb(level, sourceClass, sourceMethod, bundleName, "[" 206 + componentName + "] " + convertMsg(msg), param1); 207 } 208 209 public void logrb(Level level, String sourceClass, String sourceMethod, 210 String bundleName, String msg, Object [] params) { 211 logger.logrb(level, sourceClass, sourceMethod, bundleName, "[" 212 + componentName + "] " + convertMsg(msg), params); 213 } 214 215 public void logrb(Level level, String sourceClass, String sourceMethod, 216 String bundleName, String msg, Throwable thrown) { 217 logger.logrb(level, sourceClass, sourceMethod, bundleName, "[" 218 + componentName + "] " + convertMsg(msg), thrown); 219 } 220 221 public void removeHandler(Handler handler) throws SecurityException { 222 logger.removeHandler(handler); 223 } 224 225 public void setFilter(Filter newFilter) throws SecurityException { 226 logger.setFilter(newFilter); 227 } 228 229 public void setLevel(Level newLevel) throws SecurityException { 230 logger.setLevel(newLevel); 231 } 232 233 public void setParent(Logger parent) { 234 logger.setParent(parent); 235 } 236 237 public void setUseParentHandlers(boolean useParentHandlers) { 238 logger.setUseParentHandlers(useParentHandlers); 239 } 240 241 public void severe(String msg) { 242 logger.severe("[" 243 + componentName + "] " + convertMsg(msg)); 244 } 245 246 public void throwing(String sourceClass, String sourceMethod, 247 Throwable thrown) { 248 logger.throwing(sourceClass, sourceMethod, thrown); 249 } 250 251 public String toString() { 252 return logger.toString(); 253 } 254 255 public void warning(String msg) { 256 logger.warning("[" 257 + componentName + "] " + convertMsg(msg)); 258 } 259 260 protected String convertMsg(String msg) { 261 String out = msg; 262 if (logger.getResourceBundle() != null) { 263 Enumeration <String > enumeration = logger.getResourceBundle() 264 .getKeys(); 265 while (enumeration.hasMoreElements()) { 266 String key = enumeration.nextElement(); 267 if (key.equals(msg)) { 268 out = logger.getResourceBundle().getString(msg); 269 break; 270 } 271 } 272 } 273 return out; 274 } 275 276 } 277 | Popular Tags |