mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 11:15:53 +08:00
Add basic logging middleware
This commit is contained in:
parent
1ffe9f75f5
commit
8912bb2016
1
main.go
1
main.go
@ -65,6 +65,7 @@ func main() {
|
|||||||
defer inspector.Close()
|
defer inspector.Close()
|
||||||
|
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
|
router.Use(loggingMiddleware)
|
||||||
|
|
||||||
api := router.PathPrefix("/api").Subrouter()
|
api := router.PathPrefix("/api").Subrouter()
|
||||||
// Queue endpoints.
|
// Queue endpoints.
|
||||||
|
16
middlewares.go
Normal file
16
middlewares.go
Normal 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)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user