1 2 3 27 package org.apache.tomcat.util.log; 28 29 import org.apache.tomcat.util.log.*; 30 import java.io.Writer ; 31 import java.io.PrintWriter ; 32 import java.io.FileWriter ; 33 import java.io.File ; 34 import java.io.OutputStreamWriter ; 35 import java.io.IOException ; 36 import java.io.StringWriter ; 37 38 import java.util.*; 39 40 41 54 public class LogHandler { 55 56 protected PrintWriter sink = defaultSink; 57 protected int level = Log.INFORMATION; 58 59 60 70 public void log(String prefix, String msg, Throwable t, 71 int verbosityLevel) 72 { 73 if( sink==null ) return; 74 if( verbosityLevel > this.level ) return; 76 77 if (prefix != null) 78 sink.println(prefix + ": " + msg ); 79 else 80 sink.println( msg ); 81 82 if( t!=null ) 83 t.printStackTrace( sink ); 84 } 85 86 89 public void flush() { 90 if( sink!=null) 91 sink.flush(); 92 } 93 94 95 98 public synchronized void close() { 99 this.sink = null; 100 } 101 102 108 public void setLevel(int level) { 109 this.level = level; 110 } 111 112 115 public int getLevel() { 116 return this.level; 117 } 118 119 120 122 protected static PrintWriter defaultSink = 123 new PrintWriter ( new OutputStreamWriter (System.err), true); 124 125 131 public static void setDefaultSink(Writer w) { 132 if( w instanceof PrintWriter ) 133 defaultSink=(PrintWriter )w; 134 else 135 defaultSink = new PrintWriter (w); 136 } 137 138 140 141 142 } 143 | Popular Tags |