[go] log/slog: add Record.AttrsIter

6 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Nov 3, 2025, 8:15:21 AM (3 days ago) Nov 3
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

log/slog: add Record.AttrsIter

Fixes #61934
Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
GitHub-Last-Rev: 2e87b46228e5fe518047755da2ad522618d05d7e
GitHub-Pull-Request: golang/go#76154

Change diff

diff --git a/src/log/slog/record.go b/src/log/slog/record.go
index 3b4e68c..d7a3b54 100644
--- a/src/log/slog/record.go
+++ b/src/log/slog/record.go
@@ -5,6 +5,7 @@
package slog

import (
+ "iter"
"runtime"
"slices"
"time"
@@ -92,6 +93,13 @@
}
}

+// AttrsIter returns an iterator over every attribute in the [Record].
+func (r Record) AttrsIter() iter.Seq[Attr] {
+ return func(yield func(Attr) bool) {
+ r.Attrs(yield)
+ }
+}
+
// AddAttrs appends the given Attrs to the [Record]'s list of Attrs.
// It omits empty groups.
func (r *Record) AddAttrs(attrs ...Attr) {
diff --git a/src/log/slog/record_test.go b/src/log/slog/record_test.go
index 939dc34..a81477f 100644
--- a/src/log/slog/record_test.go
+++ b/src/log/slog/record_test.go
@@ -36,6 +36,22 @@
t.Errorf("got %v, want %v", got, want)
}
}
+
+ // Early return with iterator.
+ // Hit both loops in Record.Attrs: front and back.
+ for _, stop := range []int{2, 6} {
+ var got []Attr
+ for a := range r.AttrsIter() {
+ got = append(got, a)
+ if len(got) < stop {
+ break
+ }
+ }
+ want := as[:stop]
+ if !attrsEqual(got, want) {
+ t.Errorf("got %v, want %v", got, want)
+ }
+ }
}

func TestRecordSource(t *testing.T) {

Change information

Files:
  • M src/log/slog/record.go
  • M src/log/slog/record_test.go
Change size: S
Delta: 2 files changed, 24 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
Gerrit-Change-Number: 717300
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Nov 3, 2025, 8:15:22 AM (3 days ago) Nov 3
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. The commit message body is very brief. That can be OK if the change is trivial like correcting spelling or fixing a broken link, but usually the description should provide context for the change and explain what it does in complete sentences.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
    Gerrit-Change-Number: 717300
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 03 Nov 2025 13:15:18 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Nov 3, 2025, 8:18:03 AM (3 days ago) Nov 3
    to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Message from Gopher Robot

    Congratulations on opening your first change. Thank you for your contribution!

    Next steps:
    A maintainer will review your change and provide feedback. See
    https://go.dev/doc/contribute#review for more info and tips to get your
    patch through code review.

    Most changes in the Go project go through a few rounds of revision. This can be
    surprising to people new to the project. The careful, iterative review process
    is our way of helping mentor contributors and ensuring that their contributions
    have a lasting impact.

    During May-July and Nov-Jan the Go project is in a code freeze, during which
    little code gets reviewed or merged. If a reviewer responds with a comment like
    R=go1.11 or adds a tag like "wait-release", it means that this CL will be
    reviewed as part of the next development cycle. See https://go.dev/s/release
    for more details.

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
    Gerrit-Change-Number: 717300
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 03 Nov 2025 13:17:58 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Sean Liao (Gerrit)

    unread,
    Nov 3, 2025, 8:34:57 AM (3 days ago) Nov 3
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Jonathan Amsterdam, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Jonathan Amsterdam

    Sean Liao voted and added 1 comment

    Votes added by Sean Liao

    Hold+1

    1 comment

    Patchset-level comments
    Sean Liao . unresolved

    proposal not yet accepted.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Jonathan Amsterdam
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 13:34:48 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Jonathan Amsterdam (Gerrit)

      unread,
      Nov 3, 2025, 9:27:17 AM (3 days ago) Nov 3
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

      Jonathan Amsterdam added 1 comment

      File src/log/slog/record.go
      Line 98, Patchset 1 (Latest): return func(yield func(Attr) bool) {
      Jonathan Amsterdam . unresolved

      Could you just return `r.Attrs`?

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 14:27:10 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      unsatisfied_requirement
      open
      diffy

      Jonathan Amsterdam (Gerrit)

      unread,
      Nov 3, 2025, 9:27:21 AM (3 days ago) Nov 3
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

      Jonathan Amsterdam voted Hold+1

      Hold+1
      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 14:27:17 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Nov 3, 2025, 9:59:23 AM (3 days ago) Nov 3
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jonathan Amsterdam and Sean Liao

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #2 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jonathan Amsterdam
      • Sean Liao
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Sean Liao <se...@liao.dev>
      Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Nov 3, 2025, 10:09:14 AM (3 days ago) Nov 3
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jonathan Amsterdam and Sean Liao

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #3 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jonathan Amsterdam
      • Sean Liao
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 3
      unsatisfied_requirement
      open
      diffy

      Jonathan Amsterdam (Gerrit)

      unread,
      Nov 3, 2025, 5:02:37 PM (3 days ago) Nov 3
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Sean Liao

      Jonathan Amsterdam voted and added 2 comments

      Votes added by Jonathan Amsterdam

      Hold+1

      2 comments

      Patchset-level comments
      File-level comment, Patchset 3 (Latest):
      Jonathan Amsterdam . resolved

      Please change the commit message.

      File src/log/slog/record.go
      Line 98, Patchset 1: return func(yield func(Attr) bool) {
      Jonathan Amsterdam . resolved

      Could you just return `r.Attrs`?

      Jonathan Amsterdam

      Done

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Sean Liao
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 3
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Sean Liao <se...@liao.dev>
      Gerrit-Comment-Date: Mon, 03 Nov 2025 22:02:33 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Jonathan Amsterdam <j...@google.com>
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Nov 4, 2025, 2:55:59 AM (2 days ago) Nov 4
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jonathan Amsterdam and Sean Liao

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #4 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jonathan Amsterdam
      • Sean Liao
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Holds
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie1bd93f95f81b398fabe2f6cdff321fe6ce82597
      Gerrit-Change-Number: 717300
      Gerrit-PatchSet: 4
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
      Gerrit-Reviewer: Sean Liao <se...@liao.dev>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Sean Liao <se...@liao.dev>
      Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages