2fas-server/internal/common/http/log.go

25 lines
543 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package http
import (
"github.com/gin-gonic/gin"
2023-01-30 19:59:42 +01:00
"github.com/twofas/2fas-server/internal/common/logging"
2022-12-31 10:22:38 +01:00
)
func RequestJsonLogger() gin.HandlerFunc {
return func(c *gin.Context) {
requestLogger := logging.WithFields(logging.Fields{
"client_ip": c.ClientIP(),
"method": c.Request.Method,
"path": c.Request.URL.Path,
"request_id": c.GetString(RequestIdKey),
"correlation_id": c.GetString(CorrelationIdKey),
})
requestLogger.Info("Request")
c.Next()
requestLogger.Info("Response")
}
}