mirror of
https://github.com/labstack/echo.git
synced 2024-12-26 20:54:00 +02:00
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))
|
||
|
}
|
||
|
}
|