4 // LoggingResponseWriter
7 "github.com/gorilla/mux"
12 type LoggingResponseWriter struct {
18 func (loggingWriter *LoggingResponseWriter) WriteHeader(code int) {
19 loggingWriter.Status = code
20 loggingWriter.ResponseWriter.WriteHeader(code)
23 func (loggingWriter *LoggingResponseWriter) Write(data []byte) (int, error) {
24 loggingWriter.Length += len(data)
25 return loggingWriter.ResponseWriter.Write(data)
28 type LoggingRESTRouter struct {
32 func MakeLoggingRESTRouter() *LoggingRESTRouter {
33 router := MakeRESTRouter()
34 return (&LoggingRESTRouter{router})
37 func (loggingRouter *LoggingRESTRouter) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
38 loggingWriter := LoggingResponseWriter{200, 0, resp}
39 loggingRouter.router.ServeHTTP(&loggingWriter, req)
40 log.Printf("[%s] %s %s %d %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.Status, loggingWriter.Length)