From 46511bef0ed179d9fb672a7808c349219f835bd0 Mon Sep 17 00:00:00 2001 From: infra-bot Date: Tue, 22 Oct 2019 00:21:56 +0800 Subject: [PATCH] fix format --- gokit.go | 13 ++++++++++--- gokit_test.go | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gokit.go b/gokit.go index 3c66257..514fce4 100644 --- a/gokit.go +++ b/gokit.go @@ -54,7 +54,8 @@ const ( const ( _ Caller = iota NONE - FullPATH + FullPATHFunc + BasePathFunc BasePath ) @@ -105,11 +106,17 @@ func format(level Level, msg string) string { line int ) pc, file, line, _ = runtime.Caller(3) - if withCaller == FullPATH { + switch withCaller { + case FullPATHFunc: context = fmt.Sprintf("%s:%03d::%s", file, line, path.Base(runtime.FuncForPC(pc).Name())) - }else{ + case BasePathFunc: context = fmt.Sprintf("%s:%03d::%s", path.Base(file), line, path.Base(runtime.FuncForPC(pc).Name())) + case BasePath: + context = fmt.Sprintf("%s:%03d", path.Base(file), line) + default: + context = fmt.Sprintf("%s:%03d", path.Base(file), line) } + return fmt.Sprintf("%s\t[%3s]\t%s\t%s\n", time.Now().Format("2006-01-02 15:04:05.999"), getLevelName(level), context, msg) } else { return fmt.Sprintf("%s\t[%3s]\t%s\n", time.Now().Format("2006-01-02 15:04:05.999"), getLevelName(level), msg) diff --git a/gokit_test.go b/gokit_test.go index 81a7506..a4bde0c 100644 --- a/gokit_test.go +++ b/gokit_test.go @@ -16,7 +16,7 @@ func init() { func BenchmarkGoKit(b *testing.B) { defer Exit() - Init(SYSLOG, "test", LevelDebug, true, BasePath) + Init(SYSLOG, "test", LevelDebug, true, NoFuncName) b.ResetTimer() for i := 0; i < b.N; i++ { Info("test " + strconv.FormatInt(int64(i), 10))