Skip to content

Commit

Permalink
Beautify callback log output (go-gorm#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
liov authored and jinzhu committed Dec 5, 2019
1 parent 376a729 commit 0aba7ff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) {

messages = []interface{}{source, currentTime}

if len(values) == 2 {
//remove the line break
currentTime = currentTime[1:]
//remove the brackets
source = fmt.Sprintf("\033[35m%v\033[0m", values[1])

messages = []interface{}{currentTime, source}
}

if level == "sql" {
// duration
messages = append(messages, fmt.Sprintf(" \033[36;1m[%.2fms]\033[0m ", float64(values[2].(time.Duration).Nanoseconds()/1e4)/100.0))
Expand Down

0 comments on commit 0aba7ff

Please sign in to comment.