package httphandlers

import (
	"fmt"
	"net/http"

	"github.com/fiskerinc/cloud-services/pkg/logger"
)

func LogRequest(next http.HandlerFunc) http.HandlerFunc {
	wrapper := func(w http.ResponseWriter, r *http.Request) {
		logger.Info().
			Str("headers", fmt.Sprintf("%v", r.Header)).
			Str("ip", r.RemoteAddr).
			Str("user", GetClientID(r)).
			Msgf("%s %s", r.Method, r.RequestURI)
		next.ServeHTTP(w, r)
	}

	return wrapper
}
