Skip to content

Commit

Permalink
slog-handler-guide: fix link, mention ReplaceAttr
Browse files Browse the repository at this point in the history
- Fix a broken link.

- When discussing handler options, mention ReplaceAttr.

This were both suggested by Peter Aronoff ([email protected])
in a direct email.

Change-Id: I286142a1c5736691e32042e383f9a98e78f0fb49
Reviewed-on: https://go-review.googlesource.com/c/example/+/524758
Commit-Queue: Jonathan Amsterdam <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Bypass: Jonathan Amsterdam <[email protected]>
  • Loading branch information
jba committed Sep 1, 2023
1 parent 9fd7daa commit d9923f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion slog-handler-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
will change the behavior of all handlers that contain it.
Changes to `LevelVar`s are goroutine-safe.

You might also consider adding a `ReplaceAttr` option to your handler,
like the [one for the built-in
handlers](https://pkg.go.dev/log/slog#HandlerOptions.ReplaceAttr).
Although `ReplaceAttr` will complicate your implementation, it will also
make your handler more generally useful.

The mutex will be used to ensure that writes to the `io.Writer` happen atomically.
Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
`sync.Mutex` directly.
Expand Down Expand Up @@ -504,7 +510,9 @@ number of calls to those methods, because of the repeated copying.
That is unlikely to matter in practice, but if it bothers you,
you can use a linked list instead,
which `Handle` will have to reverse or visit recursively.
See [github.com/jba/slog/withsupport](https://github.com/jba/slog/withsupport) for an implementation.
See the
[github.com/jba/slog/withsupport](https://github.com/jba/slog/tree/main/withsupport)
package for an implementation.

#### Getting the mutex right

Expand Down
10 changes: 9 additions & 1 deletion slog-handler-guide/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
will change the behavior of all handlers that contain it.
Changes to `LevelVar`s are goroutine-safe.

You might also consider adding a `ReplaceAttr` option to your handler,
like the [one for the built-in
handlers](https://pkg.go.dev/log/slog#HandlerOptions.ReplaceAttr).
Although `ReplaceAttr` will complicate your implementation, it will also
make your handler more generally useful.

The mutex will be used to ensure that writes to the `io.Writer` happen atomically.
Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
`sync.Mutex` directly.
Expand Down Expand Up @@ -323,7 +329,9 @@ number of calls to those methods, because of the repeated copying.
That is unlikely to matter in practice, but if it bothers you,
you can use a linked list instead,
which `Handle` will have to reverse or visit recursively.
See [github.com/jba/slog/withsupport](https://github.com/jba/slog/withsupport) for an implementation.
See the
[github.com/jba/slog/withsupport](https://github.com/jba/slog/tree/main/withsupport)
package for an implementation.

#### Getting the mutex right

Expand Down

0 comments on commit d9923f6

Please sign in to comment.