fixed gofmt issue

This commit is contained in:
Torkel Ödegaard
2015-10-08 17:30:13 +02:00
parent 04eefb8480
commit 9fc91b7aa1
3 changed files with 75 additions and 73 deletions

View File

@ -18,20 +18,12 @@ package middleware
import (
"fmt"
"net/http"
"runtime"
"time"
"github.com/Unknwon/macaron"
"github.com/grafana/grafana/pkg/log"
)
var isWindows bool
func init() {
isWindows = runtime.GOOS == "windows"
}
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
func Logger() macaron.Handler {
return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) {
start := time.Now()
@ -40,20 +32,17 @@ func Logger() macaron.Handler {
c.Next()
content := fmt.Sprintf("Completed %s %v %s in %v", req.URL.Path, rw.Status(), http.StatusText(rw.Status()), time.Since(start))
if !isWindows {
switch rw.Status() {
case 200:
content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
return
case 304:
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
return
case 404:
content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
case 500:
content = fmt.Sprintf("\033[1;36m%s\033[0m", content)
}
switch rw.Status() {
case 200, 304:
content = fmt.Sprintf("%s", content)
return
case 404:
content = fmt.Sprintf("%s", content)
case 500:
content = fmt.Sprintf("%s", content)
}
log.Info(content)
}
}