From d9923f6970e9ba7e0d23aa9448ead71ea57235ae Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Fri, 1 Sep 2023 05:07:08 -0400 Subject: [PATCH] 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 Reviewed-by: Alan Donovan TryBot-Bypass: Jonathan Amsterdam --- slog-handler-guide/README.md | 10 +++++++++- slog-handler-guide/guide.md | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/slog-handler-guide/README.md b/slog-handler-guide/README.md index 89b6109a..712ec12e 100644 --- a/slog-handler-guide/README.md +++ b/slog-handler-guide/README.md @@ -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. @@ -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 diff --git a/slog-handler-guide/guide.md b/slog-handler-guide/guide.md index 7aa4d7e7..fb4664d3 100644 --- a/slog-handler-guide/guide.md +++ b/slog-handler-guide/guide.md @@ -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. @@ -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