1 29 30 package com.caucho.log; 31 32 import com.caucho.util.L10N; 33 import com.caucho.vfs.Path; 34 import com.caucho.vfs.WriteStream; 35 36 import java.io.IOException ; 37 import java.util.logging.Handler ; 38 import java.util.logging.LogRecord ; 39 40 43 public class PathHandler extends Handler { 44 private static final L10N L = new L10N(PathHandler.class); 45 46 private Path _path; 47 private String _encoding; 48 49 public PathHandler(Path path) 50 { 51 _path = path; 52 } 53 54 57 public void publish(LogRecord record) 58 { 59 if (record.getLevel().intValue() < getLevel().intValue()) 60 return; 61 62 WriteStream os = null; 63 synchronized (_path) { 64 try { 65 try { 66 os = _path.openAppend(); 67 } catch (Throwable e) { 68 _path.getParent().mkdirs(); 69 os = _path.openAppend(); 70 } 71 72 if (_encoding != null) 73 os.setEncoding(_encoding); 74 75 String msg = record.getMessage(); 76 os.println(msg); 77 } catch (Throwable e) { 78 e.printStackTrace(); 79 } finally { 80 try { 81 if (os != null) 82 os.close(); 83 } catch (IOException e) { 84 } 85 } 86 } 87 } 88 89 92 public void flush() 93 { 94 } 95 96 99 public void close() 100 { 101 } 102 103 106 public int hashCode() 107 { 108 return _path.hashCode(); 109 } 110 111 114 public boolean equals(Object o) 115 { 116 if (this == o) 117 return true; 118 else if (! (o instanceof PathHandler)) 119 return false; 120 121 PathHandler handler = (PathHandler) o; 122 123 return _path.equals(handler._path); 124 } 125 126 public String toString() 127 { 128 return "PathHandler[" + _path + "]"; 129 } 130 } 131 | Popular Tags |