From 77ddc3338f02111dde74a4e6bf118095b37e3b83 Mon Sep 17 00:00:00 2001 From: IamCathal Date: Wed, 19 Aug 2020 15:07:46 +0100 Subject: [PATCH] Fix file path logging for enableFullFilePath --- pkg/logs/log.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/logs/log.go b/pkg/logs/log.go index 3965eabb..37421625 100644 --- a/pkg/logs/log.go +++ b/pkg/logs/log.go @@ -39,7 +39,6 @@ import ( "os" "path" "runtime" - "strconv" "strings" "sync" "time" @@ -279,14 +278,25 @@ func (bl *BeeLogger) writeMsg(lm *LogMsg, v ...interface{}) error { lm.Msg = bl.prefix + " " + lm.Msg + var ( + file string + line int + ok bool + ) + if bl.enableFuncCallDepth { - _, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) + _, file, line, ok = runtime.Caller(bl.loggerFuncCallDepth) if !ok { file = "???" line = 0 } - _, filename := path.Split(file) - lm.Msg = "[" + filename + ":" + strconv.Itoa(line) + "] " + lm.Msg + + if !bl.enableFullFilePath { + _, file = path.Split(file) + } + lm.FilePath = file + lm.LineNumber = line + lm.Msg = fmt.Sprintf("[%s:%d] %s", lm.FilePath, lm.LineNumber, lm.Msg) } //set level info in front of filename info