This commit is contained in:
wangchuxiao 2023-01-12 18:09:13 +08:00
parent 31ff1cb673
commit 82c32d24a1
2 changed files with 12 additions and 1 deletions

View File

@ -3,8 +3,11 @@ package log
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/trace_log" "Open_IM/pkg/common/trace_log"
"Open_IM/pkg/utils"
"bufio" "bufio"
"context" "context"
"runtime"
"strings"
//"bufio" //"bufio"
"fmt" "fmt"
@ -252,6 +255,15 @@ func ShowLog(ctx context.Context) {
}).Infoln("rpc: ", t.ApiName) }).Infoln("rpc: ", t.ApiName)
} }
for _, v := range *t.Funcs { for _, v := range *t.Funcs {
if v.File == "" {
_, file, line, _ := runtime.Caller(1)
var s string
i := strings.SplitAfter(file, "/")
if len(i) > 3 {
s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(line)
}
v.File = s
}
if v.Err != nil { if v.Err != nil {
ctxLogger.WithFields(logrus.Fields{ ctxLogger.WithFields(logrus.Fields{
"OperationID": OperationID, "OperationID": OperationID,

View File

@ -185,7 +185,6 @@ func SetContextInfo(ctx context.Context, funcName string, logLevel logrus.Level,
if len(i) > 3 { if len(i) > 3 {
s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(line) s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(line)
} }
fmt.Println(funcInfo.FuncName, "file", s, file)
funcInfo.File = s funcInfo.File = s
*t.Funcs = append(*t.Funcs, funcInfo) *t.Funcs = append(*t.Funcs, funcInfo)
} }