1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-26 20:54:00 +02:00
echo/middleware/logger.go

33 lines
515 B
Go
Raw Normal View History

package middleware
import (
"log"
"time"
"github.com/labstack/bolt"
"github.com/labstack/gommon/color"
)
func Logger() bolt.HandlerFunc {
return func(c *bolt.Context) {
start := time.Now()
c.Next()
end := time.Now()
co := color.Green
m := c.Request.Method
p := c.Request.URL.Path
s := c.Response.Status()
switch {
case s >= 500:
co = color.Red
case s >= 400:
co = color.Yellow
case s >= 300:
co = color.Cyan
}
log.Printf("%s %s %s %s", m, p, co(s), end.Sub(start))
}
}