Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Add LoggingHTTPHandler for logging REST requests at the server-side
Browse files Browse the repository at this point in the history
  • Loading branch information
brb committed May 3, 2016
1 parent f08148c commit 9dd1fbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions common/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package common

import (
"net/http"
)

type loggingHandler struct {
next http.Handler
}

func (l *loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Log.Debugf("[http] %s %s", r.Method, r.URL.RequestURI())
l.next.ServeHTTP(w, r)
}

func LoggingHTTPHandler(h http.Handler) http.Handler {
return &loggingHandler{next: h}
}
2 changes: 1 addition & 1 deletion prog/weaver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func main() {
}
router.HandleHTTP(muxRouter)
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver)
http.Handle("/", muxRouter)
http.Handle("/", common.LoggingHTTPHandler(muxRouter))
Log.Println("Listening for HTTP control messages on", httpAddr)
go listenAndServeHTTP(httpAddr, muxRouter)
}
Expand Down

0 comments on commit 9dd1fbb

Please sign in to comment.