Files
giredore/internal/httpserver/requestlogger.go
T

32 lines
609 B
Go
Raw Normal View History

2019-10-05 21:53:22 +05:00
package httpserver
import (
// other
"time"
2019-10-05 21:53:22 +05:00
"github.com/labstack/echo"
)
func requestLogger() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ec echo.Context) error {
startTime := time.Now()
err := next(ec)
2019-10-05 21:53:22 +05:00
log.Info().
Str("From", ec.RealIP()).
Str("To", ec.Request().Host).
Str("Method", ec.Request().Method).
Str("Path", ec.Request().URL.Path).
Int64("Length", ec.Request().ContentLength).
Str("UA", ec.Request().UserAgent()).
TimeDiff("TimeMS", time.Now(), startTime).
2019-10-05 21:53:22 +05:00
Msg("HTTP request")
return err
2019-10-05 21:53:22 +05:00
}
}
}