add caller info & stdout

master v0.0.7
guohao 5 years ago
parent aeb05d2923
commit 7c2b576164
  1. 6
      gokit.go
  2. 3
      gokit_test.go

@ -55,7 +55,7 @@ const (
_ Caller = iota
NONE
FullPATH
File
BasePath
)
type Writer interface {
@ -106,9 +106,9 @@ func format(level Level, msg string) string {
)
pc, file, line, _ = runtime.Caller(3)
if withCaller == FullPATH {
context = fmt.Sprintf("%s:%d(%s)", file, line, runtime.FuncForPC(pc).Name())
context = fmt.Sprintf("%s:%d(%s)", file, line, path.Base(runtime.FuncForPC(pc).Name()))
}else{
context = fmt.Sprintf("%s:%d(%s)", path.Base(file), line, runtime.FuncForPC(pc).Name())
context = fmt.Sprintf("%s:%d(%s)", path.Base(file), line, path.Base(runtime.FuncForPC(pc).Name()))
}
return fmt.Sprintf("%s [%s] %s %s \n", time.Now().Format("2006-01-02 15:04:05.999"), getLevelName(level), context, msg)
} else {

@ -12,12 +12,11 @@ func init() {
var l Level
flag.Int("level", int(l) , "l")
flag.Parse()
println(l.Get())
}
func BenchmarkGoKit(b *testing.B) {
defer Exit()
Init(SYSLOG, "test", LevelDebug, true, BasePath)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Info("test " + strconv.FormatInt(int64(i), 10))

Loading…
Cancel
Save