1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-04 09:20:18 +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

@ -816,18 +816,27 @@ Admin:
if BConfig.RunMode == DEV || BConfig.Log.AccessLogs {
timeDur := time.Since(startTime)
var devInfo string
statusCode := context.ResponseWriter.Status
if statusCode == 0 { statusCode = 200 }
statusColor := logs.ColorByStatus(statusCode)
methodColor := logs.ColorByMethod(r.Method)
resetColor := logs.ColorByMethod("")
if findRouter {
if routerInfo != nil {
devInfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s | % -40s |", r.Method, r.URL.Path, timeDur.String(), "match", routerInfo.pattern)
devInfo = fmt.Sprintf("|%s %3d %s|%7s|%8s|%s %s %-7s %-3s r:%s", statusColor, statusCode, resetColor,
timeDur.String(), "match", methodColor, resetColor, r.Method, r.URL.Path, routerInfo.pattern)
} else {
devInfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeDur.String(), "match")
devInfo = fmt.Sprintf("|%s %3d %s|%7s|%8s|%s %s %-7s %-3s", statusColor, statusCode, resetColor,
timeDur.String(), "match", methodColor, resetColor, r.Method, r.URL.Path)
}
} else {
devInfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeDur.String(), "notmatch")
}
if DefaultAccessLogFilter == nil || !DefaultAccessLogFilter.Filter(context) {
logs.Debug(devInfo)
devInfo = fmt.Sprintf("|%s %3d %s|%7s|%8s|%s %s %-7s %-3s", statusColor, statusCode, resetColor,
timeDur.String(), "nomatch", methodColor, resetColor, r.Method, r.URL.Path)
}
logs.Debug(devInfo)
}
// Call WriteHeader if status code has been set changed