diff --git a/src/log/slog/handler.go b/src/log/slog/handler.go index 2ff85b582ef..f9c9518f3f1 100644 --- a/src/log/slog/handler.go +++ b/src/log/slog/handler.go @@ -294,7 +294,7 @@ func (h *commonHandler) handle(r Record) error { } // source if h.opts.AddSource { - state.appendAttr(Any(SourceKey, r.source())) + state.appendAttr(Any(SourceKey, r.Source())) } key = MessageKey msg := r.Message diff --git a/src/log/slog/handler_test.go b/src/log/slog/handler_test.go index 8ce34526d0b..e2ab6820944 100644 --- a/src/log/slog/handler_test.go +++ b/src/log/slog/handler_test.go @@ -530,7 +530,7 @@ func TestJSONAndTextHandlers(t *testing.T) { }, } { r := NewRecord(testTime, LevelInfo, "message", callerPC(2)) - line := strconv.Itoa(r.source().Line) + line := strconv.Itoa(r.Source().Line) r.AddAttrs(test.attrs...) var buf bytes.Buffer opts := HandlerOptions{ReplaceAttr: test.replace, AddSource: test.addSource} diff --git a/src/log/slog/logger_test.go b/src/log/slog/logger_test.go index 9efd4ed0e91..dff2f71b07a 100644 --- a/src/log/slog/logger_test.go +++ b/src/log/slog/logger_test.go @@ -185,7 +185,7 @@ func TestCallDepth(t *testing.T) { const wantFunc = "log/slog.TestCallDepth" const wantFile = "logger_test.go" wantLine := startLine + count*2 - got := h.r.source() + got := h.r.Source() gotFile := filepath.Base(got.File) if got.Function != wantFunc || gotFile != wantFile || got.Line != wantLine { t.Errorf("got (%s, %s, %d), want (%s, %s, %d)", diff --git a/src/log/slog/record.go b/src/log/slog/record.go index 97c87019a6a..5a06f4f8fd6 100644 --- a/src/log/slog/record.go +++ b/src/log/slog/record.go @@ -211,11 +211,11 @@ func (s *Source) group() Value { return GroupValue(as...) } -// source returns a Source for the log event. +// Source returns a Source for the log event. // If the Record was created without the necessary information, // or if the location is unavailable, it returns a non-nil *Source // with zero fields. -func (r Record) source() *Source { +func (r Record) Source() *Source { fs := runtime.CallersFrames([]uintptr{r.PC}) f, _ := fs.Next() return &Source{ diff --git a/src/log/slog/record_test.go b/src/log/slog/record_test.go index 931ab660418..575c7221f0b 100644 --- a/src/log/slog/record_test.go +++ b/src/log/slog/record_test.go @@ -56,7 +56,7 @@ func TestRecordSource(t *testing.T) { pc = callerPC(test.depth + 1) } r := NewRecord(time.Time{}, 0, "", pc) - got := r.source() + got := r.Source() if i := strings.LastIndexByte(got.File, '/'); i >= 0 { got.File = got.File[i+1:] }