Skip to content

Commit d9923f6

Browse files
committed
slog-handler-guide: fix link, mention ReplaceAttr
- Fix a broken link. - When discussing handler options, mention ReplaceAttr. This were both suggested by Peter Aronoff (peteraronoff@fastmail.com) in a direct email. Change-Id: I286142a1c5736691e32042e383f9a98e78f0fb49 Reviewed-on: https://go-review.googlesource.com/c/example/+/524758 Commit-Queue: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Bypass: Jonathan Amsterdam <jba@google.com>
1 parent 9fd7daa commit d9923f6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

slog-handler-guide/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
147147
will change the behavior of all handlers that contain it.
148148
Changes to `LevelVar`s are goroutine-safe.
149149

150+
You might also consider adding a `ReplaceAttr` option to your handler,
151+
like the [one for the built-in
152+
handlers](https://pkg.go.dev/log/slog#HandlerOptions.ReplaceAttr).
153+
Although `ReplaceAttr` will complicate your implementation, it will also
154+
make your handler more generally useful.
155+
150156
The mutex will be used to ensure that writes to the `io.Writer` happen atomically.
151157
Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
152158
`sync.Mutex` directly.
@@ -504,7 +510,9 @@ number of calls to those methods, because of the repeated copying.
504510
That is unlikely to matter in practice, but if it bothers you,
505511
you can use a linked list instead,
506512
which `Handle` will have to reverse or visit recursively.
507-
See [github.com/jba/slog/withsupport](https://github.com/jba/slog/withsupport) for an implementation.
513+
See the
514+
[github.com/jba/slog/withsupport](https://github.com/jba/slog/tree/main/withsupport)
515+
package for an implementation.
508516

509517
#### Getting the mutex right
510518

slog-handler-guide/guide.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
109109
will change the behavior of all handlers that contain it.
110110
Changes to `LevelVar`s are goroutine-safe.
111111

112+
You might also consider adding a `ReplaceAttr` option to your handler,
113+
like the [one for the built-in
114+
handlers](https://pkg.go.dev/log/slog#HandlerOptions.ReplaceAttr).
115+
Although `ReplaceAttr` will complicate your implementation, it will also
116+
make your handler more generally useful.
117+
112118
The mutex will be used to ensure that writes to the `io.Writer` happen atomically.
113119
Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
114120
`sync.Mutex` directly.
@@ -323,7 +329,9 @@ number of calls to those methods, because of the repeated copying.
323329
That is unlikely to matter in practice, but if it bothers you,
324330
you can use a linked list instead,
325331
which `Handle` will have to reverse or visit recursively.
326-
See [github.com/jba/slog/withsupport](https://github.com/jba/slog/withsupport) for an implementation.
332+
See the
333+
[github.com/jba/slog/withsupport](https://github.com/jba/slog/tree/main/withsupport)
334+
package for an implementation.
327335

328336
#### Getting the mutex right
329337

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy