From b951ba027eaadb81646174dd8b58dd32532dfd77 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Fri, 24 Jul 2026 01:44:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(log):=20caller=20=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E6=A1=86=E6=9E=B6=20session.go=EF=BC=8CSQL?= =?UTF-8?q?=20=E6=97=A5=E5=BF=97=E5=BD=92=E5=9B=A0=E7=9B=B4=E8=BE=BE?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E5=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit session 存取中间层不是业务发起点,此前 session 读写触发的 SQL 日志 caller 落在 session.go:29/136,业务帧被挤到 "<-" 之后,Seq 归因噪音大。 Co-authored-by: Cursor --- log/caller_filter_test.go | 31 +++++++++++++++++++++++++++++++ log/logger.go | 5 +++++ 2 files changed, 36 insertions(+) create mode 100644 log/caller_filter_test.go diff --git a/log/caller_filter_test.go b/log/caller_filter_test.go new file mode 100644 index 0000000..c946f30 --- /dev/null +++ b/log/caller_filter_test.go @@ -0,0 +1,31 @@ +package log + +import "testing" + +// isInfrastructureFile 的入参是 shortenPath 后的短路径(最后两段) +func TestIsInfrastructureFile(t *testing.T) { + cases := []struct { + file string + want bool + }{ + // hotime 框架的 session/context 属中间层,应跳过 + {"hotime@v1.7.302/session.go", true}, + {"hotimev1.5/session.go", true}, + {"hotime@v1.7.302/context.go", true}, + // 框架基础设施目录 + {"db/db.go", true}, + {"cache/cache_db.go", true}, + {"zerolog/log.go", true}, + // hotime 根包其余文件不跳过(application.go、code.go 的日志是框架自身行为) + {"hotime@v1.7.302/application.go", false}, + {"hotime@v1.7.302/code.go", false}, + // 业务侧同名文件不受影响(路径不含 hotime) + {"wx/session.go", false}, + {"app/user.go", false}, + } + for _, c := range cases { + if got := isInfrastructureFile(c.file); got != c.want { + t.Errorf("isInfrastructureFile(%q) = %v, want %v", c.file, got, c.want) + } + } +} diff --git a/log/logger.go b/log/logger.go index 22bbf76..6b23dcc 100644 --- a/log/logger.go +++ b/log/logger.go @@ -890,6 +890,11 @@ func isInfrastructureFile(file string) bool { if strings.HasSuffix(file, "/context.go") || strings.HasSuffix(file, "\\context.go") { return true } + // session.go 是 session 存取中间层,永远不是业务发起点; + // 跳过后 session 读写触发的 SQL 日志 caller 直接落业务帧(而非 session.go:29 <- 业务帧) + if strings.HasSuffix(file, "/session.go") || strings.HasSuffix(file, "\\session.go") { + return true + } } return false