Skip to content

Commit 2d61f44

Browse files
committed
slog: remove Attr.AppendValue
Attr.AppendValue was originally intended to be a convenient and more efficient way of formatting Attr values. But there is no one clearly right way to format them, and the efficiency argument doesn't really hold water: AppendValue skips the redundant but cheap type check that occurs in switch a.Kind() { case IntKind: ... a.Int() .. but then formats Times and Durations as strings instead of integers. We keep it internally to help out in a couple of places, but overall it's better if Handler implementations do their own value formatting. For casual use, fmt.Sprint(a.Value()) is fine. Change-Id: Ie265f1ee5daf5f8002bfc2b70f4bf461cb07a10b Reviewed-on: https://go-review.googlesource.com/c/exp/+/430098 Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent d6a8ba4 commit 2d61f44

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

slog/attr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ func (a1 Attr) Equal(a2 Attr) bool {
279279
}
280280
}
281281

282-
// AppendValue appends a text representation of the Attr's value to dst.
282+
// appendValue appends a text representation of the Attr's value to dst.
283283
// The value is formatted as with fmt.Sprint.
284-
func (a Attr) AppendValue(dst []byte) []byte {
284+
func (a Attr) appendValue(dst []byte) []byte {
285285
switch a.Kind() {
286286
case StringKind:
287287
return append(dst, a.str()...)

slog/attr_safe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ func (a Attr) String() string {
5858
return a.str()
5959
}
6060
var buf []byte
61-
return string(a.AppendValue(buf))
61+
return string(a.appendValue(buf))
6262
}

slog/attr_unsafe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ func (a Attr) String() string {
7878
return s
7979
}
8080
var buf []byte
81-
return string(a.AppendValue(buf))
81+
return string(a.appendValue(buf))
8282
}

slog/text_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (ap *textAppender) appendAttrValue(a Attr) error {
136136
}
137137
ap.appendString(fmt.Sprint(a.Value()))
138138
default:
139-
*ap.buf() = a.AppendValue(*ap.buf())
139+
*ap.buf() = a.appendValue(*ap.buf())
140140
}
141141
return nil
142142
}

0 commit comments

Comments
 (0)