Dump changes
This commit is contained in:
parent
e12550a643
commit
aac2ea1b74
25 changed files with 129 additions and 76 deletions
34
pkg/brainbuffer/infrastructure/server/middleware.go
Normal file
34
pkg/brainbuffer/infrastructure/server/middleware.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/rs/zerolog/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Logger() echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) (err error) {
|
||||
req := c.Request()
|
||||
res := c.Response()
|
||||
start := time.Now()
|
||||
if err = next(c); err != nil {
|
||||
c.Error(err)
|
||||
}
|
||||
stop := time.Now()
|
||||
|
||||
log.Info().
|
||||
Str("remote_ip", c.RealIP()).
|
||||
Str("host", req.Host).
|
||||
Str("uri", req.RequestURI).
|
||||
Str("method", req.Method).
|
||||
Str("path", req.URL.Path).
|
||||
Str("user_agent", req.UserAgent()).
|
||||
Int("status", res.Status).
|
||||
Str("latency", stop.Sub(start).String()).
|
||||
Send()
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue