refactor: better request logging
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/deluan/navidrome/engine"
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/server/subsonic/responses"
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
@@ -177,5 +178,14 @@ func SendResponse(w http.ResponseWriter, r *http.Request, payload *responses.Sub
|
||||
w.Header().Set("Content-Type", "application/xml")
|
||||
response, _ = xml.Marshal(payload)
|
||||
}
|
||||
if payload.Status == "ok" {
|
||||
if log.CurrentLevel() >= log.LevelTrace {
|
||||
log.Info(r.Context(), "API: Successful response", "status", "OK", "body", string(response))
|
||||
} else {
|
||||
log.Info(r.Context(), "API: Successful response", "status", "OK")
|
||||
}
|
||||
} else {
|
||||
log.Warn(r.Context(), "API: Failed response", "error", payload.Error.Code, "message", payload.Error.Message)
|
||||
}
|
||||
w.Write(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user