Fever API: add client IP in middleware logs
This commit is contained in:
parent
019cf79704
commit
4e07b549a2
1 changed files with 4 additions and 3 deletions
|
@ -24,9 +24,10 @@ func newMiddleware(s *storage.Storage) *middleware {
|
||||||
|
|
||||||
func (m *middleware) serve(next http.Handler) http.Handler {
|
func (m *middleware) serve(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
clientIP := request.ClientIP(r)
|
||||||
apiKey := r.FormValue("api_key")
|
apiKey := r.FormValue("api_key")
|
||||||
if apiKey == "" {
|
if apiKey == "" {
|
||||||
logger.Info("[Fever] No API key provided")
|
logger.Info("[Fever] [ClientIP=%s] No API key provided", clientIP)
|
||||||
json.OK(w, r, newAuthFailureResponse())
|
json.OK(w, r, newAuthFailureResponse())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -39,12 +40,12 @@ func (m *middleware) serve(next http.Handler) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
logger.Info("[Fever] No user found with this API key")
|
logger.Info("[Fever] [ClientIP=%s] No user found with this API key", clientIP)
|
||||||
json.OK(w, r, newAuthFailureResponse())
|
json.OK(w, r, newAuthFailureResponse())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("[Fever] User #%d is authenticated with user agent %q", user.ID, r.UserAgent())
|
logger.Info("[Fever] [ClientIP=%s] User #%d is authenticated with user agent %q", clientIP, user.ID, r.UserAgent())
|
||||||
m.store.SetLastLogin(user.ID)
|
m.store.SetLastLogin(user.ID)
|
||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
Loading…
Reference in a new issue