1 18 package org.objectweb.util.monolog.wrapper.printwriter; 19 20 import org.objectweb.util.monolog.api.Logger; 21 import org.objectweb.util.monolog.api.BasicLevel; 22 import org.objectweb.util.monolog.api.LoggerFactory; 23 import org.objectweb.util.monolog.api.Loggable; 24 25 import java.io.PrintStream ; 26 27 36 public class PrintStreamImpl 37 extends PrintStream 38 implements Loggable { 39 40 41 protected Logger logger = null; 42 protected LoggerFactory loggerFactory = null; 43 44 47 protected String currentLine = ""; 48 49 protected int level; 50 51 57 public PrintStreamImpl(Logger l) throws NullPointerException { 58 super(new EmptyOutputStream()); 59 if (l == null) 60 throw new NullPointerException ("Logger parameter is null"); 61 logger = l; 62 level = BasicLevel.DEBUG; 63 } 64 65 72 public PrintStreamImpl(Logger l, int level) throws NullPointerException { 73 super(new EmptyOutputStream()); 74 if (l == null) 75 throw new NullPointerException ("Logger parameter is null"); 76 logger = l; 77 this.level = level; 78 } 79 80 84 public int getLevel() { 85 return level; 86 } 87 88 92 public void setLevel(int level) { 93 this.level = level; 94 } 95 96 99 102 public Logger getLogger() { 103 return logger; 104 } 105 106 109 public void setLogger(Logger logger) { 110 this.logger = logger; 111 } 112 113 116 public LoggerFactory getLoggerFactory() { 117 return loggerFactory; 118 } 119 120 123 public void setLoggerFactory(LoggerFactory lf) { 124 this.loggerFactory = lf; 125 } 126 127 130 131 134 public void write(byte[] bytes) { 135 currentLine += new String (bytes); 136 } 137 138 141 public boolean equals(Object o) { 142 return o instanceof PrintStreamImpl 143 && ((PrintStreamImpl) o).logger == logger; 144 } 145 146 149 public void flush() { 150 } 151 152 155 protected Object clone() throws CloneNotSupportedException { 156 throw new CloneNotSupportedException (); 157 } 158 159 162 public void close() { 163 } 164 165 168 public String toString() { 169 return logger.toString(); 170 } 171 172 176 public boolean checkError() { 177 return false; 178 } 179 180 181 184 protected void setError() { 185 } 186 187 190 public void write(int i) { 191 currentLine += i; 192 } 193 194 197 public void write(byte[] bytes, int i, int i1) { 198 currentLine += new String (bytes, i, i1); 199 } 200 201 204 public void print(boolean b) { 205 currentLine += b; 206 } 207 208 211 public void print(char c) { 212 currentLine += c; 213 } 214 215 218 public void print(int i) { 219 currentLine += i; 220 } 221 222 225 public void print(long l) { 226 currentLine += l; 227 } 228 229 232 public void print(float v) { 233 currentLine += v; 234 } 235 236 239 public void print(double v) { 240 currentLine += v; 241 } 242 243 246 public void print(char[] chars) { 247 logger.log(level, currentLine + new String (chars)); 248 currentLine = ""; 249 } 250 251 254 public void print(String s) { 255 currentLine += s; 256 } 257 258 261 public void print(Object o) { 262 currentLine += o; 263 } 264 265 268 public void println() { 269 logger.log(level, currentLine); 270 currentLine = ""; 271 } 272 273 278 public void println(boolean b) { 279 logger.log(level, currentLine + b); 280 currentLine = ""; 281 } 282 283 288 public void println(char c) { 289 logger.log(level, currentLine + c); 290 currentLine = ""; 291 } 292 293 298 public void println(int i) { 299 logger.log(level, currentLine + i); 300 currentLine = ""; 301 } 302 303 308 public void println(long l) { 309 logger.log(level, currentLine + l); 310 currentLine = ""; 311 } 312 313 318 public void println(float v) { 319 logger.log(level, currentLine + v); 320 currentLine = ""; 321 } 322 323 328 public void println(double v) { 329 logger.log(level, currentLine + v); 330 currentLine = ""; 331 } 332 333 338 public void println(char[] chars) { 339 logger.log(level, currentLine + new String (chars)); 340 currentLine = ""; 341 } 342 343 348 public void println(String s) { 349 logger.log(level, currentLine + s); 350 currentLine = ""; 351 } 352 353 358 public void println(Object o) { 359 logger.log(level, currentLine + o); 360 currentLine = ""; 361 } 362 } 363 | Popular Tags |