Skip to content

Commit

Permalink
iterate caller stack more stronger
Browse files Browse the repository at this point in the history
  • Loading branch information
VarusHsu committed Feb 7, 2024
1 parent b9887bc commit 13387ac
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ func defaultLogger(sql string, durationNano int64) {
var file string
var line int
var ok bool
for i := 0; i < 16; i++ {
_, file, line, ok = runtime.Caller(i)
var stackDepth = 2
for _, file, line, ok = runtime.Caller(stackDepth); ok; stackDepth++ {
// `!strings.HasPrefix(file, srcPrefix)` jump out when using sqlingo as dependent package
// `strings.HasSuffix(file, "_test.go")` jump out when executing unit test cases
// `!ok` this is so terrible for something unexpected happened
if !ok || !strings.HasPrefix(file, srcPrefix) || strings.HasSuffix(file, "_test.go") {
if !strings.HasPrefix(file, srcPrefix) || strings.HasSuffix(file, "_test.go") {
break
}
}
Expand Down

0 comments on commit 13387ac

Please sign in to comment.