adjust log entry format

remotes/origin/HEAD
fangdingjun 7 years ago
parent e36040bfce
commit 41879e9ec2

@ -62,39 +62,43 @@ func (f *TextFormatter) Format(level log.Level, msg string, logger *log.Logger)
timeStr := time.Now().Format(f.TimeFormat)
buf.WriteString(timeStr)
// level
buf.WriteByte(' ')
if f.isterm {
buf.WriteString(level.ColorString())
} else {
buf.WriteString(level.String())
}
/*
// host
buf.WriteByte(' ')
buf.Write(f.host)
// host
buf.WriteByte(' ')
buf.Write(f.host)
// name
buf.WriteByte(' ')
buf.Write(f.app)
// name
buf.WriteByte(' ')
buf.Write(f.app)
// pid
buf.WriteByte(' ')
buf.Write(f.pid)
// pid
buf.WriteByte(' ')
buf.Write(f.pid)
*/
// file, line
file, line := FilelineCaller(4)
buf.WriteByte(' ')
buf.WriteString(" [")
buf.WriteString(file)
buf.WriteByte(':')
buf.WriteString(strconv.Itoa(line))
buf.WriteString("]")
// msg
// level
buf.WriteByte(' ')
if f.isterm {
buf.WriteString(level.ColorString())
} else {
buf.WriteString(level.String())
}
// msg
buf.WriteString(": ")
buf.WriteString(msg)
// newline
buf.WriteByte('\n')
if msg[len(msg)-1] != '\n' {
buf.WriteByte('\n')
}
return buf.Bytes()
}

@ -1,6 +1,7 @@
package formatters
import (
"path"
"runtime"
"strings"
)
@ -17,19 +18,20 @@ func FilelineCaller(skip int) (file string, line int) {
if strings.Contains(file, "go-log/") {
continue
}
// file = pkg/file.go
n := 0
for i := len(file) - 1; i > 0; i-- {
if file[i] == '/' {
n++
if n >= 2 {
file = file[i+1:]
break
/*
// file = pkg/file.go
n := 0
for i := len(file) - 1; i > 0; i-- {
if file[i] == '/' {
n++
if n >= 2 {
file = file[i+1:]
break
}
}
}
}
return file, line
*/
return path.Base(file), line
}
return "???", 0

Loading…
Cancel
Save