1 8 9 package net.sourceforge.chaperon.ant; 10 11 import org.apache.commons.logging.Log; 12 13 import org.apache.tools.ant.Project; 14 15 21 public final class AntLog implements Log 22 { 23 private final Project project; 25 private boolean use_level = false; 26 private int antMsgLevel = Project.MSG_ERR; 27 28 33 public AntLog(Project project) 34 { 35 this.project = project; 36 } 37 38 44 public AntLog(Project project, int antMsgLevel) 45 { 46 this.project = project; 47 this.antMsgLevel = antMsgLevel; 48 use_level = true; 49 } 50 51 58 public void trace(Object message) 59 { 60 if ((use_level) && (antMsgLevel==Project.MSG_DEBUG)) 61 project.log(message.toString()); 62 63 project.log(message.toString(), Project.MSG_DEBUG); 64 } 65 66 74 public void trace(Object message, Throwable t) 75 { 76 if ((use_level) && (antMsgLevel==Project.MSG_DEBUG)) 77 project.log(message+":"+toString(t)); 78 79 project.log(message+":"+toString(t), Project.MSG_DEBUG); 80 } 81 82 92 public boolean isTraceEnabled() 93 { 94 if (use_level) 95 return antMsgLevel==Project.MSG_DEBUG; 96 97 return true; 98 } 99 100 107 public void debug(Object message) 108 { 109 if ((use_level) && (antMsgLevel==Project.MSG_DEBUG)) 110 project.log(message.toString()); 111 112 project.log(message.toString(), Project.MSG_DEBUG); 113 } 114 115 123 public void debug(Object message, Throwable t) 124 { 125 if ((use_level) && (antMsgLevel==Project.MSG_DEBUG)) 126 project.log(message+":"+toString(t)); 127 128 project.log(message+":"+toString(t), Project.MSG_DEBUG); 129 } 130 131 141 public boolean isDebugEnabled() 142 { 143 if (use_level) 144 return antMsgLevel==Project.MSG_DEBUG; 145 146 return true; 147 } 148 149 156 public void info(Object message) 157 { 158 if ((use_level) && (antMsgLevel==Project.MSG_INFO)) 159 project.log(message.toString()); 160 161 project.log(message.toString(), Project.MSG_INFO); 162 } 163 164 172 public void info(Object message, Throwable t) 173 { 174 if ((use_level) && (antMsgLevel==Project.MSG_INFO)) 175 project.log(message+":"+toString(t)); 176 177 project.log(message+":"+toString(t), Project.MSG_INFO); 178 } 179 180 190 public boolean isInfoEnabled() 191 { 192 if (use_level) 193 return antMsgLevel==Project.MSG_INFO; 194 195 return true; 196 } 197 198 205 public void warn(Object message) 206 { 207 if ((use_level) && (antMsgLevel==Project.MSG_WARN)) 208 project.log(message.toString()); 209 210 project.log(message.toString(), Project.MSG_WARN); 211 } 212 213 221 public void warn(Object message, Throwable t) 222 { 223 if ((use_level) && (antMsgLevel==Project.MSG_WARN)) 224 project.log(message+":"+toString(t)); 225 226 project.log(message+":"+toString(t), Project.MSG_WARN); 227 } 228 229 239 public boolean isWarnEnabled() 240 { 241 if (use_level) 242 return antMsgLevel==Project.MSG_WARN; 243 244 return true; 245 } 246 247 254 public void error(Object message) 255 { 256 if ((use_level) && (antMsgLevel==Project.MSG_ERR)) 257 project.log(message.toString()); 258 259 project.log(message.toString(), Project.MSG_ERR); 260 } 261 262 270 public void error(Object message, Throwable t) 271 { 272 if ((use_level) && (antMsgLevel==Project.MSG_ERR)) 273 project.log(message+":"+toString(t)); 274 275 project.log(message+":"+toString(t), Project.MSG_ERR); 276 } 277 278 288 public boolean isErrorEnabled() 289 { 290 if (use_level) 291 return antMsgLevel==Project.MSG_ERR; 292 293 return true; 294 } 295 296 303 public void fatal(Object message) 304 { 305 if ((use_level) && (antMsgLevel==Project.MSG_ERR)) 306 project.log(message.toString()); 307 308 project.log(message.toString(), Project.MSG_ERR); 309 } 310 311 319 public void fatal(Object message, Throwable t) 320 { 321 if ((use_level) && (antMsgLevel==Project.MSG_ERR)) 322 project.log(message+":"+toString(t)); 323 324 project.log(message+":"+toString(t), Project.MSG_ERR); 325 } 326 327 337 public boolean isFatalEnabled() 338 { 339 if (use_level) 340 return antMsgLevel==Project.MSG_ERR; 341 342 return true; 343 } 344 345 private String toString(Throwable t) 346 { 347 StringBuffer buffer = new StringBuffer (); 348 if (t!=null) 349 { 350 buffer.append(" <"); 351 buffer.append(t.toString()); 352 buffer.append(">"); 353 354 java.io.StringWriter sw = new java.io.StringWriter (1024); 355 java.io.PrintWriter pw = new java.io.PrintWriter (sw); 356 t.printStackTrace(pw); 357 pw.close(); 358 buffer.append(sw.toString()); 359 } 360 361 return buffer.toString(); 362 } 363 } 364 | Popular Tags |