mirror of
https://github.com/gabehf/sonarr-anime-importer.git
synced 2026-03-08 23:18:14 -07:00
add status code and latency to request log
This commit is contained in:
parent
06882336fa
commit
186e00577d
1 changed files with 17 additions and 2 deletions
|
|
@ -36,10 +36,25 @@ func newRebuildStaleIdMapMiddleware(idMap *ConcurrentMap) func(http.HandlerFunc)
|
|||
}
|
||||
}
|
||||
|
||||
type statusResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
status int
|
||||
}
|
||||
|
||||
func (w *statusResponseWriter) WriteHeader(code int) {
|
||||
w.status = code
|
||||
w.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func loggerMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Print(RequestString(r))
|
||||
next.ServeHTTP(w, r)
|
||||
start := time.Now()
|
||||
|
||||
srw := &statusResponseWriter{ResponseWriter: w, status: http.StatusOK} // default to 200
|
||||
next.ServeHTTP(srw, r)
|
||||
|
||||
duration := time.Since(start)
|
||||
log.Printf("%s - %d %s - %v", RequestString(r), srw.status, http.StatusText(srw.status), duration)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue