fix filename in log

remotes/origin/HEAD
fangdingjun 7 years ago
parent f16df80d3e
commit 11d07df44e

@ -9,7 +9,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/subchen/go-log" "github.com/fangdingjun/go-log"
) )
// JSONFormatter is a json formatter // JSONFormatter is a json formatter
@ -41,7 +41,7 @@ func (f *JSONFormatter) Format(level log.Level, msg string, logger *log.Logger)
data := make(map[string]interface{}, 8) data := make(map[string]interface{}, 8)
// file, line // file, line
file, line := FilelineCaller(5) file, line := FilelineCaller(4)
data["time"] = time.Now().Format(f.TimeFormat) data["time"] = time.Now().Format(f.TimeFormat)
data["level"] = level.String() data["level"] = level.String()

@ -8,7 +8,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/subchen/go-log" "github.com/fangdingjun/go-log"
) )
var ( var (
@ -83,7 +83,7 @@ func (f *TextFormatter) Format(level log.Level, msg string, logger *log.Logger)
buf.Write(f.pid) buf.Write(f.pid)
// file, line // file, line
file, line := FilelineCaller(5) file, line := FilelineCaller(4)
buf.WriteByte(' ') buf.WriteByte(' ')
buf.WriteString(file) buf.WriteString(file)
buf.WriteByte(':') buf.WriteByte(':')

@ -13,6 +13,11 @@ func FilelineCaller(skip int) (file string, line int) {
return "???", 0 return "???", 0
} }
//fmt.Printf("%s:%d\n", file, line)
if strings.Contains(file, "go-log/") {
continue
}
// file = pkg/file.go // file = pkg/file.go
n := 0 n := 0
for i := len(file) - 1; i > 0; i-- { for i := len(file) - 1; i > 0; i-- {
@ -24,11 +29,8 @@ func FilelineCaller(skip int) (file string, line int) {
} }
} }
} }
if !strings.HasPrefix(file, "go-log/") {
return file, line return file, line
} }
}
return "???", 0 return "???", 0
} }

Loading…
Cancel
Save