You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/log/file_line_hk.go

42 lines
852 B

/*
** description("get the name and line number of the calling file hook").
** copyright('tuoyun,www.tuoyun.net').
** author("fg,Gordon@tuoyun.net").
** time(2021/3/16 11:26).
*/
package log
import (
2 years ago
"OpenIM/pkg/utils"
"github.com/sirupsen/logrus"
"runtime"
"strings"
)
type fileHook struct{}
func newFileHook() *fileHook {
return &fileHook{}
}
func (f *fileHook) Levels() []logrus.Level {
return logrus.AllLevels
}
3 years ago
//func (f *fileHook) Fire(entry *logrus.Entry) error {
// entry.Map["FilePath"] = findCaller(6)
2 years ago
// utils.GetSelfFuncName()
3 years ago
// return nil
//}
2 years ago
func (f *fileHook) Fire(entry *logrus.Entry) error {
var s string
_, file, line, _ := runtime.Caller(8)
i := strings.SplitAfter(file, "/")
if len(i) > 3 {
s = i[len(i)-3] + i[len(i)-2] + i[len(i)-1] + ":" + utils.IntToString(line)
}
2 years ago
entry.Data["FilePath"] = s
return nil
}