fix: ignore .gen.go suffix in logger to get the real caller when using gen #6697

This commit is contained in:
0xJacky 2024-01-08 12:39:24 +08:00
parent 87decced23
commit 57d6553b9b
No known key found for this signature in database
GPG Key ID: B6E4A6E4A561BAF0

View File

@ -35,7 +35,8 @@ func FileWithLineNum() string {
// the second caller usually from gorm internal, so set i start from 2 // the second caller usually from gorm internal, so set i start from 2
for i := 2; i < 15; i++ { for i := 2; i < 15; i++ {
_, file, line, ok := runtime.Caller(i) _, file, line, ok := runtime.Caller(i)
if ok && (!strings.HasPrefix(file, gormSourceDir) || strings.HasSuffix(file, "_test.go")) { if ok && (!strings.HasPrefix(file, gormSourceDir) || strings.HasSuffix(file, "_test.go")) &&
!strings.HasSuffix(file, ".gen.go") {
return file + ":" + strconv.FormatInt(int64(line), 10) return file + ":" + strconv.FormatInt(int64(line), 10)
} }
} }