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

This commit is contained in:
Jacky 2024-01-12 18:09:22 +09:00 committed by GitHub
parent 940358e0dd
commit 0123dd4509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

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)
} }
} }