mirror of
https://github.com/beego/bee.git
synced 2024-12-22 15:10:49 +00:00
Merge pull request #35 from odiel/master
Log levels as constants, printing time with logs
This commit is contained in:
commit
0b5cef8bf7
18
util.go
18
util.go
@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
||||
@ -41,6 +42,11 @@ const (
|
||||
Magenta
|
||||
//NRed = uint8(31) // Normal
|
||||
EndColor = "\033[0m"
|
||||
|
||||
TRAC = "TRAC"
|
||||
ERRO = "ERRO"
|
||||
WARN = "WARN"
|
||||
SUCC = "SUCC"
|
||||
)
|
||||
|
||||
// colorLog colors log and print to stdout.
|
||||
@ -80,20 +86,22 @@ func colorLog(format string, a ...interface{}) {
|
||||
log = clog + log
|
||||
}
|
||||
|
||||
fmt.Print(log)
|
||||
var currentTime = time.Now()
|
||||
|
||||
fmt.Print(currentTime.Format("2006-01-02 03:04:05 "+log))
|
||||
}
|
||||
|
||||
// getColorLevel returns colored level string by given level.
|
||||
func getColorLevel(level string) string {
|
||||
level = strings.ToUpper(level)
|
||||
switch level {
|
||||
case "TRAC":
|
||||
case TRAC:
|
||||
return fmt.Sprintf("\033[%dm%s\033[0m", Blue, level)
|
||||
case "ERRO":
|
||||
case ERRO:
|
||||
return fmt.Sprintf("\033[%dm%s\033[0m", Red, level)
|
||||
case "WARN":
|
||||
case WARN:
|
||||
return fmt.Sprintf("\033[%dm%s\033[0m", Magenta, level)
|
||||
case "SUCC":
|
||||
case SUCC:
|
||||
return fmt.Sprintf("\033[%dm%s\033[0m", Green, level)
|
||||
default:
|
||||
return level
|
||||
|
Loading…
Reference in New Issue
Block a user