1 28 29 package com.caucho.http.log; 30 31 import com.caucho.util.Alarm; 32 import com.caucho.util.CharBuffer; 33 import com.caucho.util.CompileException; 34 import com.caucho.util.ExceptionWrapper; 35 import com.caucho.util.QDate; 36 import com.caucho.vfs.WriteStream; 37 38 import javax.servlet.ServletContext ; 39 import javax.servlet.ServletException ; 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import java.io.IOException ; 43 44 47 public class ErrorLog extends AbstractErrorLog { 48 56 public void log(String message, 57 HttpServletRequest request, 58 HttpServletResponse response, 59 ServletContext application) 60 throws IOException 61 { 62 WriteStream logStream = getLogStream(); 63 64 if (logStream == null) 65 return; 66 67 CharBuffer cb = CharBuffer.allocate(); 68 69 QDate.formatLocal(cb, Alarm.getCurrentTime(), "[%Y/%m/%d %H:%M:%S] "); 70 71 cb.append(message); 72 73 logStream.log(cb.close()); 74 75 logStream.flush(); 76 } 77 78 85 public void log(String message, 86 Throwable e, 87 HttpServletRequest request, 88 HttpServletResponse response, 89 ServletContext application) 90 throws IOException 91 { 92 WriteStream logStream = getLogStream(); 93 94 if (logStream == null) 95 return; 96 97 Throwable t = e; 98 while (t != null) { 99 e = t; 100 101 if (e instanceof ServletException ) 102 t = ((ServletException ) e).getRootCause(); 103 else if (e instanceof ExceptionWrapper) 104 t = ((ExceptionWrapper) e).getRootCause(); 105 else 106 t = null; 107 } 108 109 CharBuffer cb = CharBuffer.allocate(); 110 111 QDate.formatLocal(cb, Alarm.getCurrentTime(), "[%Y/%m/%d %H:%M:%S] "); 112 113 cb.append(message); 114 115 logStream.log(cb.close()); 116 117 if (e != null && ! (e instanceof CompileException)) 118 logStream.log(e); 119 120 logStream.flush(); 121 } 122 123 126 public void destroy() 127 throws IOException 128 { 129 } 130 } 131 | Popular Tags |