1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-12 08:00:40 +00:00

Enhanced logging during DEV mode

This commit is contained in:
Faissal Elamraoui
2016-06-17 15:39:16 +02:00
committed by Faissal Elamraoui
parent 1fe2226c11
commit 2bd743fcff
2 changed files with 61 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import (
"io"
"sync"
"time"
"net/http"
)
type logWriter struct {
@ -80,3 +81,48 @@ func formatTimeHeader(when time.Time) ([]byte, int) {
return buf[0:], d
}
var (
green = string([]byte{27, 91, 57, 55, 59, 52, 50, 109})
white = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
yellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
blue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109})
magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
reset = string([]byte{27, 91, 48, 109})
)
func ColorByStatus(code int) string {
switch {
case code >= 200 && code < 300:
return green
case code >= 300 && code < 400:
return white
case code >= 400 && code < 500:
return yellow
default:
return red
}
}
func ColorByMethod(method string) string {
switch method {
case http.MethodGet:
return blue
case http.MethodPost:
return cyan
case http.MethodPut:
return yellow
case http.MethodDelete:
return red
case http.MethodPatch:
return green
case http.MethodHead:
return magenta
case http.MethodOptions:
return white
default:
return reset
}
}