1 20 package org.apache.cactus.integration.ant.util; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.Target; 25 import org.apache.tools.ant.Task; 26 27 42 public final class AntLog implements Log 43 { 44 45 47 50 public static final Log NULL = new Log() 51 { 52 53 55 58 public boolean isFatalEnabled() 59 { 60 return false; 61 } 62 63 66 public void fatal(Object theMessage) 67 { 68 } 70 71 74 public void fatal(Object theMessage, Throwable theThrowable) 75 { 76 } 78 79 82 public boolean isErrorEnabled() 83 { 84 return false; 85 } 86 87 90 public void error(Object theMessage) 91 { 92 } 94 95 98 public void error(Object theMessage, Throwable theThrowable) 99 { 100 } 102 103 106 public boolean isWarnEnabled() 107 { 108 return false; 109 } 110 111 114 public void warn(Object theMessage) 115 { 116 } 118 119 122 public void warn(Object theMessage, Throwable theThrowable) 123 { 124 } 126 127 130 public boolean isInfoEnabled() 131 { 132 return false; 133 } 134 135 138 public void info(Object theMessage) 139 { 140 } 142 143 146 public void info(Object theMessage, Throwable theThrowable) 147 { 148 } 150 151 154 public boolean isDebugEnabled() 155 { 156 return false; 157 } 158 159 162 public void debug(Object theMessage) 163 { 164 } 166 167 170 public void debug(Object theMessage, Throwable theThrowable) 171 { 172 } 174 175 178 public boolean isTraceEnabled() 179 { 180 return false; 181 } 182 183 186 public void trace(Object theMessage) 187 { 188 } 190 191 194 public void trace(Object theMessage, Throwable theThrowable) 195 { 196 } 198 199 }; 200 201 203 206 private Project project; 207 208 211 private Target target; 212 213 216 private Task task; 217 218 220 225 public AntLog(Task theTask) 226 { 227 this.project = theTask.getProject(); 228 this.task = theTask; 229 } 230 231 236 public AntLog(Target theTarget) 237 { 238 this.project = theTarget.getProject(); 239 this.target = theTarget; 240 } 241 242 247 public AntLog(Project theProject) 248 { 249 this.project = theProject; 250 } 251 252 254 257 public boolean isFatalEnabled() 258 { 259 return true; 260 } 261 262 265 public void fatal(Object theMessage) 266 { 267 log(theMessage, null, Project.MSG_ERR); 268 } 269 270 273 public void fatal(Object theMessage, Throwable theThrowable) 274 { 275 log(theMessage, theThrowable, Project.MSG_ERR); 276 } 277 278 281 public boolean isErrorEnabled() 282 { 283 return true; 284 } 285 286 289 public void error(Object theMessage) 290 { 291 log(theMessage, null, Project.MSG_ERR); 292 } 293 294 297 public void error(Object theMessage, Throwable theThrowable) 298 { 299 log(theMessage, theThrowable, Project.MSG_ERR); 300 } 301 302 305 public boolean isWarnEnabled() 306 { 307 return true; 308 } 309 310 313 public void warn(Object theMessage) 314 { 315 log(theMessage, null, Project.MSG_WARN); 316 } 317 318 321 public void warn(Object theMessage, Throwable theThrowable) 322 { 323 log(theMessage, theThrowable, Project.MSG_WARN); 324 } 325 326 329 public boolean isInfoEnabled() 330 { 331 return true; 332 } 333 334 337 public void info(Object theMessage) 338 { 339 log(theMessage, null, Project.MSG_INFO); 340 } 341 342 345 public void info(Object theMessage, Throwable theThrowable) 346 { 347 log(theMessage, theThrowable, Project.MSG_INFO); 348 } 349 350 353 public boolean isDebugEnabled() 354 { 355 return true; 356 } 357 358 361 public void debug(Object theMessage) 362 { 363 log(theMessage, null, Project.MSG_DEBUG); 364 } 365 366 369 public void debug(Object theMessage, Throwable theThrowable) 370 { 371 log(theMessage, theThrowable, Project.MSG_DEBUG); 372 } 373 374 377 public boolean isTraceEnabled() 378 { 379 return true; 380 } 381 382 385 public void trace(Object theMessage) 386 { 387 log(theMessage, null, Project.MSG_VERBOSE); 388 } 389 390 393 public void trace(Object theMessage, Throwable theThrowable) 394 { 395 log(theMessage, theThrowable, Project.MSG_VERBOSE); 396 } 397 398 400 407 private void log(Object theMessage, Throwable theThrowable, int theLogLevel) 408 { 409 String message = String.valueOf(theMessage); 410 if (theThrowable != null) 411 { 412 message += " (" + theThrowable.getMessage() + ")"; 413 } 414 if (this.task != null) 415 { 416 this.project.log(this.task, message, theLogLevel); 417 } 418 else if (this.target != null) 419 { 420 this.project.log(this.target, message, theLogLevel); 421 } 422 else 423 { 424 this.project.log(message, theLogLevel); 425 } 426 } 427 428 } 429 | Popular Tags |