mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 07:42:31 +08:00
fixed gofmt issue
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user