1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00
echo/middleware/logger.go
Vishal Rana 7c9a0b6489 initial commit
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-03-01 09:45:13 -08:00

33 lines
523 B
Go

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