mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
7c9a0b6489
Signed-off-by: Vishal Rana <vr@labstack.com>
33 lines
523 B
Go
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))
|
|
}
|
|
}
|