1 28 29 package org.apache.commons.transaction.util; 30 31 import java.io.PrintWriter ; 32 33 39 public class PrintWriterLogger implements LoggerFacade { 40 41 protected PrintWriter printWriter; 42 protected String name; 43 protected boolean debug; 44 45 public PrintWriterLogger(PrintWriter printWriter, String name, boolean debug) { 46 this.printWriter = printWriter; 47 this.name = name; 48 this.debug = debug; 49 } 50 51 public LoggerFacade createLogger(String newName) { 52 return new PrintWriterLogger(this.printWriter, newName, this.debug); 53 } 54 55 public void logInfo(String message) { 56 log("INFO", message); 57 } 58 59 public void logFine(String message) { 60 if (debug) 61 log("FINE", message); 62 } 63 64 public boolean isFineEnabled() { 65 return debug; 66 } 67 68 public void logFiner(String message) { 69 if (debug) 70 log("FINER", message); 71 } 72 73 public boolean isFinerEnabled() { 74 return debug; 75 } 76 77 public void logFinest(String message) { 78 if (debug) 79 log("FINEST", message); 80 } 81 82 public boolean isFinestEnabled() { 83 return debug; 84 } 85 86 public void logWarning(String message) { 87 log("WARNING", message); 88 } 89 90 public void logWarning(String message, Throwable t) { 91 log("WARNING", message); 92 t.printStackTrace(printWriter); 93 } 94 95 public void logSevere(String message) { 96 log("SEVERE", message); 97 } 98 99 public void logSevere(String message, Throwable t) { 100 log("SEVERE", message); 101 t.printStackTrace(printWriter); 102 } 103 104 protected void log(String level, String message) { 105 printWriter.write(name + "(" + level + ":" + message); 106 printWriter.flush(); 107 } 108 } 109 | Popular Tags |