1
0
mirror of https://github.com/labstack/echo.git synced 2026-05-16 09:48:24 +02:00

Created a website #29

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-04-18 21:53:38 -07:00
parent f134ea3aea
commit 141b4302ae
5 changed files with 175 additions and 10 deletions
+10 -10
View File
@@ -6,30 +6,30 @@ import (
"github.com/labstack/echo"
"github.com/labstack/gommon/color"
"github.com/mattn/go-colorable"
)
func Logger(h echo.HandlerFunc) (echo.HandlerFunc, error) {
log.SetOutput(colorable.NewColorableStdout())
func Logger(h echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
start := time.Now()
h(c)
if err := h(c); err != nil {
return err
}
end := time.Now()
col := color.Green
m := c.Request.Method
p := c.Request.URL.Path
s := c.Response.Status()
n := c.Response.Status()
switch {
case s >= 500:
case n >= 500:
col = color.Red
case s >= 400:
case n >= 400:
col = color.Yellow
case s >= 300:
case n >= 300:
col = color.Cyan
}
log.Printf("%s %s %s %s", m, p, col(s), end.Sub(start))
log.Printf("%s %s %s %s", m, p, col(n), end.Sub(start))
return nil
}, nil
}
}