From 7c2b576164757f6303e17efd025490ac134a1de0 Mon Sep 17 00:00:00 2001 From: guohao Date: Thu, 5 Sep 2019 12:51:19 +0800 Subject: [PATCH] add caller info & stdout --- gokit.go | 6 +++--- gokit_test.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gokit.go b/gokit.go index 367d0e6..3062256 100644 --- a/gokit.go +++ b/gokit.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 { diff --git a/gokit_test.go b/gokit_test.go index a3dba25..81a7506 100644 --- a/gokit_test.go +++ b/gokit_test.go @@ -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))