featurer/server/internal/services/core/http/logger.go

30 lines
630 B
Go
Raw Permalink Normal View History

package http
import (
"log/slog"
"time"
"github.com/gin-gonic/gin"
)
func (h *http) requestLogger(serverName string) gin.HandlerFunc {
return func(ctx *gin.Context) {
startTime := time.Now()
ctx.Next()
slog.Info(
"HTTP request processed",
"service", subsystem,
"server", serverName,
"client-ip", ctx.ClientIP(),
"user-agent", ctx.Request.UserAgent(),
"path", ctx.Request.Method+" "+ctx.Request.URL.String(),
"request-size", ctx.Request.ContentLength,
"response-code", ctx.Writer.Status(),
"response-length", ctx.Writer.Size(),
"response-time", time.Since(startTime).String(),
)
}
}