Add basic logging middleware

This commit is contained in:
Ken Hibino 2020-12-07 07:14:30 -08:00
parent 1ffe9f75f5
commit 8912bb2016
2 changed files with 17 additions and 0 deletions

View File

@ -65,6 +65,7 @@ func main() {
defer inspector.Close()
router := mux.NewRouter()
router.Use(loggingMiddleware)
api := router.PathPrefix("/api").Subrouter()
// Queue endpoints.

16
middlewares.go Normal file
View File

@ -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)
})
}