1 18 19 package org.objectweb.util.monolog.wrapper.printwriter; 20 21 import org.objectweb.util.monolog.api.Logger; 22 import org.objectweb.util.monolog.api.BasicLevel; 23 import org.objectweb.util.monolog.api.Loggable; 24 import org.objectweb.util.monolog.api.LoggerFactory; 25 26 import java.io.PrintWriter ; 27 28 37 public class PrintWriterImpl 38 extends PrintWriter 39 implements Loggable { 40 41 43 46 protected Logger logger = null; 47 protected LoggerFactory loggerFactory = null; 48 49 protected int level; 50 51 54 protected String currentLine = ""; 55 56 59 protected boolean errors = false; 60 61 67 public PrintWriterImpl(Logger l) throws NullPointerException { 68 super(new EmptyWriter()); 69 if (l==null) 70 throw new NullPointerException ("Logger parameter is null"); 71 logger = l; 72 level = BasicLevel.DEBUG; 73 } 74 75 82 public PrintWriterImpl(Logger logger, 83 LoggerFactory loggerFactory) throws NullPointerException { 84 this(logger); 85 if (loggerFactory==null) 86 throw new NullPointerException ("LoggerFactory parameter is null"); 87 this.loggerFactory = loggerFactory; 88 } 89 90 97 public PrintWriterImpl(Logger l, int level) throws NullPointerException { 98 super(new EmptyWriter()); 99 if (l==null) 100 throw new NullPointerException ("Logger parameter is null"); 101 logger = l; 102 this.level = level; 103 } 104 105 public int getLevel() { 106 return level; 107 } 108 109 public void setLevel(int level) { 110 this.level = level; 111 } 112 113 116 119 public Logger getLogger() { 120 return logger; 121 } 122 123 126 public void setLogger(Logger logger) { 127 this.logger = logger; 128 } 129 130 133 public LoggerFactory getLoggerFactory() { 134 return loggerFactory; 135 } 136 137 140 public void setLoggerFactory(LoggerFactory lf) { 141 this.loggerFactory = lf; 142 } 143 144 147 150 public boolean checkError() { 151 if (currentLine.length()>0) { 152 logger.log(level, currentLine); 153 currentLine = ""; 154 } 155 return errors; 156 } 157 160 public void close() { 161 if (currentLine.length()>0) { 162 logger.log(level, currentLine); 163 currentLine = ""; 164 } 165 } 166 167 170 public void flush() { 171 if (currentLine.length()>0) { 172 logger.log(level, currentLine); 173 currentLine = ""; 174 } 175 } 176 177 180 public void print(boolean x) { 181 currentLine += x; 182 } 183 184 187 public void print(char x) { 188 currentLine += x; 189 } 190 191 194 public void print(char[] x) { 195 currentLine += new String (x); 196 } 197 198 201 public void print(double x) { 202 currentLine += x; 203 } 204 205 208 public void print(float x) { 209 currentLine += x; 210 } 211 212 215 public void print(int x) { 216 currentLine += x; 217 } 218 219 222 public void print(long x) { 223 currentLine += x; 224 } 225 226 229 public void print(Object x) { 230 currentLine += x; 231 } 232 233 236 public void print(String x) { 237 currentLine += x; 238 } 239 240 243 public void println() { 244 logger.log(level, currentLine); 245 currentLine = ""; 246 } 247 248 251 public void println(boolean x) { 252 logger.log(level, currentLine + x); 253 currentLine = ""; 254 } 255 256 259 public void println(char x) { 260 logger.log(level, currentLine + x); 261 currentLine = ""; 262 } 263 264 267 public void println(char[] x) { 268 logger.log(level, currentLine + new String (x)); 269 currentLine = ""; 270 } 271 275 public void println(double x) { 276 logger.log(level, currentLine + x); 277 currentLine = ""; 278 } 279 280 283 public void println(float x) { 284 logger.log(level, currentLine + x); 285 currentLine = ""; 286 } 287 288 291 public void println(int x) { 292 logger.log(level, currentLine + x); 293 currentLine = ""; 294 } 295 296 297 300 public void println(long x) { 301 logger.log(level, currentLine + x); 302 currentLine = ""; 303 } 304 305 308 public void println(Object x) { 309 logger.log(level, currentLine + x); 310 currentLine = ""; 311 } 312 313 316 public void println(String x) { 317 logger.log(level, currentLine + x); 318 currentLine = ""; 319 } 320 321 324 protected void setError() { 325 errors = true; 326 logger.log(BasicLevel.ERROR, currentLine + "PrintWriter error"); 327 currentLine = ""; 328 } 329 330 333 public void write(char[] buf) { 334 currentLine += new String (buf); 335 } 336 337 340 public void write(char[] buf, int off, int len) { 341 currentLine += new String (buf, off, len); 342 } 343 344 347 public void write(int c) { 348 currentLine += c; 349 } 350 351 354 public void write(String s) { 355 currentLine += s; 356 } 357 358 361 public void write(String s, int off, int len) { 362 currentLine += (s!=null ? s.substring(off, len) : ""); 363 } 364 365 } 366 | Popular Tags |