1 5 6 7 package org.joseki.logging.java; 8 9 import java.io.* ; 10 import java.util.logging.*; 11 12 17 18 public class StreamHandlerFlush extends StreamHandler 19 { 20 OutputStream output = null ; 21 22 public StreamHandlerFlush() 23 { 24 super() ; 25 configure2() ; 26 super.setOutputStream(System.out); 27 output = System.out ; 28 } 29 30 public StreamHandlerFlush(OutputStream out, Formatter formatter) 31 { 32 super(out, formatter) ; 33 output = out ; 34 configure2() ; 35 } 36 37 42 private void configure2() 43 { 44 String cname = StreamHandlerFlush.class.getName(); 45 46 LogManager manager = LogManager.getLogManager(); 47 48 String tmp = manager.getProperty(cname + ".level"); 50 if (tmp == null) 51 tmp = "INFO"; 52 setLevel(Level.parse(tmp)); 53 54 tmp = manager.getProperty(cname + ".filter"); 56 try 57 { 58 if (tmp != null) 59 { 60 Class clz = ClassLoader.getSystemClassLoader().loadClass(tmp); 61 setFilter((Filter) clz.newInstance()); 62 } 63 } 64 catch (Exception ex) 65 { 66 } 70 71 tmp = manager.getProperty(cname + ".formatter"); 73 if (tmp == null) 74 tmp = OneLineFormatter.class.getName(); 75 try 76 { 77 Class clz = ClassLoader.getSystemClassLoader().loadClass(tmp); 78 setFormatter((Formatter) clz.newInstance()); 79 } 80 catch (Exception ex) 81 { 82 } 86 87 try 89 { 90 setEncoding(manager.getProperty(cname + ".encoding")); 91 } 92 catch (Exception ex) 93 { 94 try 95 { 96 setEncoding(null); 97 } 98 catch (Exception ex2) 99 { 100 } 103 } 104 } 105 public void publish(LogRecord record) 106 { 107 super.publish(record) ; 108 super.flush() ; 109 } 111 112 } 113 114 115 141 | Popular Tags |