Skip to content

Commit 202b0b9

Browse files
jbaeric
authored andcommitted
log/slog: clarify the limits of TextHandler output parseability
Give an example illustrating the problem with dots inside groups or keys. Clarify that to fix it in general, you need to do more than escape the keys, since that won't distinguish the group "a.b" from the two groups "a" and "b". Updates golang#56345. Change-Id: Ide301899c548d50b0a1f18e93e93d6e11ad485cf Reviewed-on: https://go-review.googlesource.com/c/go/+/478199 Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent cd187aa commit 202b0b9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/log/slog/text_handler.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (h *TextHandler) WithGroup(name string) Handler {
6868
// If the AddSource option is set and source information is available,
6969
// the key is "source" and the value is output as FILE:LINE.
7070
//
71-
// The message's key "msg".
71+
// The message's key is "msg".
7272
//
7373
// To modify these or other attributes, or remove them from the output, use
7474
// [HandlerOptions.ReplaceAttr].
@@ -80,9 +80,13 @@ func (h *TextHandler) WithGroup(name string) Handler {
8080
// characters, non-printing characters, '"' or '='.
8181
//
8282
// Keys inside groups consist of components (keys or group names) separated by
83-
// dots. No further escaping is performed. If it is necessary to reconstruct the
84-
// group structure of a key even in the presence of dots inside components, use
85-
// [HandlerOptions.ReplaceAttr] to escape the keys.
83+
// dots. No further escaping is performed.
84+
// Thus there is no way to determine from the key "a.b.c" whether there
85+
// are two groups "a" and "b" and a key "c", or a single group "a.b" and a key "c",
86+
// or single group "a" and a key "b.c".
87+
// If it is necessary to reconstruct the group structure of a key
88+
// even in the presence of dots inside components, use
89+
// [HandlerOptions.ReplaceAttr] to encode that information in the key.
8690
//
8791
// Each call to Handle results in a single serialized call to
8892
// io.Writer.Write.

0 commit comments

Comments
 (0)