func getLogEntry(r *http.Request) Logger {
	entry, _ := middleware.GetLogEntry(r).(*StructuredLoggerEntry)
	return entry.Logger
}
Helper methods used by the application to get the request-scoped
logger entry and set additional fields between handlers.

This is a useful pattern to use to set state on the entry as it
passes through the handler chain, which at any point can be logged
with a call to .Print(), .Info(), etc.
GetLogEntry get log entry.
package log
import (
	"context"
	"fmt"
	"net/http"
	"time"
	"github.com/go-chi/chi/v5/middleware"
	"github.com/oxyno-zeta/s3-proxy/pkg/s3-proxy/utils"
	"github.com/sirupsen/logrus"
)
func HTTPAddLoggerToContextMiddleware() func(next http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
			logger := getLogEntry(r)
			ctx := context.WithValue(r.Context(), loggerContextKey, logger)
			r = r.WithContext(ctx)
			h.ServeHTTP(rw, r)
		})
	}
}
func NewStructuredLogger(
	logger Logger,
	getTraceID func(r *http.Request) string,
) func(next http.Handler) http.Handler {
	return middleware.RequestLogger(&StructuredLogger{
		Logger:     logger,
		GetTraceID: getTraceID,
	})
}
type StructuredLogger struct {
	Logger     Logger
	GetTraceID func(r *http.Request) string
}
func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry {
	entry := &StructuredLoggerEntry{Logger: l.Logger}
	logFields := map[string]interface{}{}
	traceIDStr := l.GetTraceID(r)
	if traceIDStr != "" {
		logFields["span_id"] = traceIDStr
	}
	if reqID := middleware.GetReqID(r.Context()); reqID != "" {
		logFields["req_id"] = reqID
	}
	logFields["http_scheme"] = utils.GetRequestScheme(r)
	logFields["http_proto"] = r.Proto
	logFields["http_method"] = r.Method
	logFields["remote_addr"] = r.RemoteAddr
	logFields["user_agent"] = r.UserAgent()
	logFields["client_ip"] = utils.ClientIP(r)
	logFields["uri"] = utils.GetRequestURI(r)
	entry.Logger = entry.Logger.WithFields(logFields)
	entry.Logger.Debug("request started")
	return entry
}
type StructuredLoggerEntry struct {
	Logger Logger
}
func (l *StructuredLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
	l.Logger = l.Logger.WithFields(logrus.Fields{
		"resp_status":       status,
		"resp_bytes_length": bytes,
		"resp_elapsed_ms":   float64(elapsed.Nanoseconds()) / 1000000.0,  
	})
	logFunc := l.Logger.Infoln
	if status >= http.StatusMultipleChoices && status < http.StatusBadRequest {
		logFunc = l.Logger.Warnln
	}
	if status >= http.StatusBadRequest {
		logFunc = l.Logger.Errorln
	}
	logFunc("request complete")
}
func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte) {
	l.Logger = l.Logger.WithFields(logrus.Fields{
		"stack": string(stack),
		"panic": fmt.Sprintf("%+v", v),
	})
}