diff --git a/main.go b/main.go index ed29ab3..7a93c0a 100644 --- a/main.go +++ b/main.go @@ -65,6 +65,7 @@ func main() { defer inspector.Close() router := mux.NewRouter() + router.Use(loggingMiddleware) api := router.PathPrefix("/api").Subrouter() // Queue endpoints. diff --git a/middlewares.go b/middlewares.go new file mode 100644 index 0000000..69869ad --- /dev/null +++ b/middlewares.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "time" +) + +func loggingMiddleware(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(os.Stdout, "%v \"%s %s\"\n", + time.Now().Format(time.RFC3339), r.Method, r.URL) + h.ServeHTTP(w, r) + }) +}