1 Star 0 Fork 1

flanche / echo

forked from guapian / echo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logger.go 632 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yasuhiro Matsumoto 提交于 2015-03-31 12:35 . colorful logger on windows
package middleware
import (
"log"
"time"
"github.com/labstack/echo"
"github.com/labstack/gommon/color"
"github.com/mattn/go-colorable"
)
func Logger(h echo.HandlerFunc) echo.HandlerFunc {
log.SetOutput(colorable.NewColorableStdout())
return echo.HandlerFunc(func(c *echo.Context) {
start := time.Now()
h(c)
end := time.Now()
col := color.Green
m := c.Request.Method
p := c.Request.URL.Path
s := c.Response.Status()
switch {
case s >= 500:
col = color.Red
case s >= 400:
col = color.Yellow
case s >= 300:
col = color.Cyan
}
log.Printf("%s %s %s %s", m, p, col(s), end.Sub(start))
})
}
1
https://gitee.com/flanche/echo.git
git@gitee.com:flanche/echo.git
flanche
echo
echo
v0.0.8

搜索帮助