diff --git a/config.go b/config.go index 84f8cf39..8a819dad 100644 --- a/config.go +++ b/config.go @@ -277,6 +277,7 @@ func init() { if err != nil { fmt.Println("init console log error:", err) } + BeeLogger.SetLogFuncCallDepth(true) err = ParseConfig() if err != nil && !os.IsNotExist(err) { diff --git a/logs/log.go b/logs/log.go index 341df572..b61388e6 100644 --- a/logs/log.go +++ b/logs/log.go @@ -154,7 +154,10 @@ func (bl *BeeLogger) writerMsg(loglevel int, msg string) error { lm := new(logMsg) lm.level = loglevel if bl.enableFuncCallDepth { - _, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth) + _, file, line, ok := runtime.Caller(bl.loggerFuncCallDepth + 1) + if !ok { + _, file, line, ok = runtime.Caller(bl.loggerFuncCallDepth) + } if ok { _, filename := path.Split(file) lm.msg = fmt.Sprintf("[%s:%d] %s", filename, line, msg)