aboutsummaryrefslogtreecommitdiff
path: root/src/log/slog/handler.go
diff options
context:
space:
mode:
authorErnesto Alejandro Santana Hidalgo <ernesto.alejandrosantana@gmail.com>2025-05-04 04:30:25 +0000
committerJonathan Amsterdam <jba@google.com>2025-05-06 03:58:07 -0700
commit044ca4e5c878c785e2c69e5ebcb3d44bf97abc9f (patch)
tree39ad811b9de590fb703e152ee5e43ad92964ac11 /src/log/slog/handler.go
parent35b4fd9f373cbe13778eb259a19c496c9c613a1f (diff)
downloadgo-044ca4e5c878c785e2c69e5ebcb3d44bf97abc9f.tar.xz
log/slog: export Source method in Record for custom handler support
Currently, the `source` method in `slog.Record` is not accessible to custom handlers, requiring developers to re-implement logic for retrieving source location information. This commit exports the `source` method as `Source`, enabling consistent access for custom logging handlers and reducing code redundancy. Fixes #70280 Change-Id: I3eb3bc60658abc5de95697a10bddd11ab54c6e13 GitHub-Last-Rev: bd81afe5a502bf0e2d03c30d0f5199a532cc4c62 GitHub-Pull-Request: golang/go#70281 Reviewed-on: https://go-review.googlesource.com/c/go/+/626976 Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/log/slog/handler.go')
-rw-r--r--src/log/slog/handler.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/log/slog/handler.go b/src/log/slog/handler.go
index 66eea02aa5..e56be5f494 100644
--- a/src/log/slog/handler.go
+++ b/src/log/slog/handler.go
@@ -299,7 +299,11 @@ func (h *commonHandler) handle(r Record) error {
}
// source
if h.opts.AddSource {
- state.appendAttr(Any(SourceKey, r.source()))
+ src := r.Source()
+ if src == nil {
+ src = &Source{}
+ }
+ state.appendAttr(Any(SourceKey, src))
}
key = MessageKey
msg := r.Message