From 9dd1fbba39d3f092655cb1d8ea2bd9b84952c166 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Fri, 22 Apr 2016 15:03:46 +0100 Subject: [PATCH] Add LoggingHTTPHandler for logging REST requests at the server-side --- common/http.go | 18 ++++++++++++++++++ prog/weaver/main.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 common/http.go diff --git a/common/http.go b/common/http.go new file mode 100644 index 00000000..2f4a1b3c --- /dev/null +++ b/common/http.go @@ -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} +} diff --git a/prog/weaver/main.go b/prog/weaver/main.go index cb297117..ff10d44e 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -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) }