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>
This commit is contained in:
Jonathan Amsterdam 2023-09-01 05:07:08 -04:00
Родитель 9fd7daa707
Коммит d9923f6970
2 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -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. will change the behavior of all handlers that contain it.
Changes to `LevelVar`s are goroutine-safe. 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. 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 Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
`sync.Mutex` directly. `sync.Mutex` directly.
@ -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, That is unlikely to matter in practice, but if it bothers you,
you can use a linked list instead, you can use a linked list instead,
which `Handle` will have to reverse or visit recursively. 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 #### Getting the mutex right

Просмотреть файл

@ -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. will change the behavior of all handlers that contain it.
Changes to `LevelVar`s are goroutine-safe. 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. 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 Unusually, `IndentHandler` holds a pointer to a `sync.Mutex` rather than holding a
`sync.Mutex` directly. `sync.Mutex` directly.
@ -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, That is unlikely to matter in practice, but if it bothers you,
you can use a linked list instead, you can use a linked list instead,
which `Handle` will have to reverse or visit recursively. 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 #### Getting the mutex right