From 5d8d7fc00b1089719fb0d8a21c4179d925ddb994 Mon Sep 17 00:00:00 2001 From: XuShuo Date: Sun, 18 Feb 2024 14:31:58 +0800 Subject: [PATCH] Revert "iterate caller stack more stronger" This reverts commit 13387ac23ec7346f20b0cfd6a53052165b7671c6. --- database.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/database.go b/database.go index 4550771..5a29a0f 100644 --- a/database.go +++ b/database.go @@ -89,11 +89,12 @@ func defaultLogger(sql string, durationNano int64) { var file string var line int var ok bool - var stackDepth = 2 - for _, file, line, ok = runtime.Caller(stackDepth); ok; stackDepth++ { + for i := 0; i < 16; i++ { + _, file, line, ok = runtime.Caller(i) // `!strings.HasPrefix(file, srcPrefix)` jump out when using sqlingo as dependent package // `strings.HasSuffix(file, "_test.go")` jump out when executing unit test cases - if !strings.HasPrefix(file, srcPrefix) || strings.HasSuffix(file, "_test.go") { + // `!ok` this is so terrible for something unexpected happened + if !ok || !strings.HasPrefix(file, srcPrefix) || strings.HasSuffix(file, "_test.go") { break } }