2019-10-05 21:53:22 +05:00
|
|
|
package httpserver
|
|
|
|
|
|
|
|
import (
|
2020-04-25 13:47:19 +05:00
|
|
|
"time"
|
|
|
|
|
2019-10-05 21:53:22 +05:00
|
|
|
"github.com/labstack/echo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func requestLogger() echo.MiddlewareFunc {
|
|
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
2021-11-20 23:06:40 +05:00
|
|
|
return func(ectx echo.Context) error {
|
2020-04-25 13:47:19 +05:00
|
|
|
startTime := time.Now()
|
|
|
|
|
2021-11-20 23:06:40 +05:00
|
|
|
err := next(ectx)
|
2020-04-25 13:47:19 +05:00
|
|
|
|
2019-10-05 21:53:22 +05:00
|
|
|
log.Info().
|
2021-11-20 23:06:40 +05:00
|
|
|
Str("From", ectx.RealIP()).
|
|
|
|
Str("To", ectx.Request().Host).
|
|
|
|
Str("Method", ectx.Request().Method).
|
|
|
|
Str("Path", ectx.Request().URL.Path).
|
|
|
|
Int64("Length", ectx.Request().ContentLength).
|
|
|
|
Str("UA", ectx.Request().UserAgent()).
|
2020-04-25 13:47:19 +05:00
|
|
|
TimeDiff("TimeMS", time.Now(), startTime).
|
2019-10-05 21:53:22 +05:00
|
|
|
Msg("HTTP request")
|
|
|
|
|
2020-04-25 13:47:19 +05:00
|
|
|
return err
|
2019-10-05 21:53:22 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|