Fixes fileline in formatters

remotes/r/develop
Guoqiang Chen 7 years ago
parent 690752443e
commit fcfbf90991

@ -0,0 +1,25 @@
package main
import (
"os"
"github.com/subchen/go-log"
"github.com/subchen/go-log/formatters"
)
func main() {
log.Info("hello", 123)
log.Warn("hello", 123)
log.Default.Formatter = new(formatters.TextFormatter)
log.Infoln("hello", "world")
log.Warnln("hello", "world")
newLog := &log.Logger{
Level: log.INFO,
Formatter: new(formatters.JSONFormatter),
Out: os.Stdout,
}
newLog.Infof("hello %v", 123)
newLog.Warnf("hello %v", 123)
}

@ -41,7 +41,7 @@ func (f JSONFormatter) Format(level log.Level, msg string, logger *log.Logger) [
data := make(map[string]interface{}, 8)
// file, line
file, line := FilelineCaller(7)
file, line := FilelineCaller(5)
data["time"] = time.Now().Format(f.TimeFormat)
data["level"] = level.String()

@ -83,14 +83,14 @@ func (f TextFormatter) Format(level log.Level, msg string, logger *log.Logger) [
buf.Write(f.pid)
// file, line
file, line := FilelineCaller(7)
file, line := FilelineCaller(5)
buf.WriteByte(' ')
buf.WriteString(file)
buf.WriteByte(':')
buf.WriteString(strconv.Itoa(line))
buf.WriteByte('"')
// msg
buf.WriteByte(' ')
buf.WriteString(msg)
// newline

@ -24,7 +24,7 @@ func FilelineCaller(skip int) (file string, line int) {
}
}
if !strings.HasPrefix(file, "log/") {
if !strings.HasPrefix(file, "go-log/") {
return file, line
}
}

Loading…
Cancel
Save