Skip to content

Commit a16ef21

Browse files
committed
slog-handler-guide: minor prose tweaks
Change-Id: Ie5299ec0f6e9d1936281152290edf397a0956b90 Reviewed-on: https://go-review.googlesource.com/c/example/+/514055 Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Ian Cottrell <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 344698f commit a16ef21

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

slog-handler-guide/README.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ such as gathering key-value pairs into `Attr`s, and then call one or more
4444
and the output methods.
4545

4646
An output method fulfills the main role of a logger: producing log output.
47-
Here is an example call to an output method:
47+
Here is a call to an output method:
4848

4949
logger.Info("hello", "key", value)
5050

@@ -69,7 +69,6 @@ A logger's `With` method calls its handler's `WithAttrs` method.
6969

7070
The `WithGroup` method is used to avoid avoid key collisions in large programs
7171
by establishing separate namespaces.
72-
7372
This call creates a new `Logger` value with a group named "g":
7473

7574
logger = logger.WithGroup("g")
@@ -140,8 +139,8 @@ func New(out io.Writer, opts *Options) *IndentHandler {
140139

141140
We'll support only one option, the ability to set a minimum level in order to
142141
supress detailed log output.
143-
Handlers should always use the `slog.Leveler` type for this option.
144-
`Leveler` is implemented by both `Level` and `LevelVar`.
142+
Handlers should always declare this option to be a `slog.Leveler`.
143+
The `slog.Leveler` interface is implemented by both `Level` and `LevelVar`.
145144
A `Level` value is easy for the user to provide,
146145
but changing the level of multiple handlers requires tracking them all.
147146
If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
@@ -220,7 +219,7 @@ groups established by `WithGroup`.
220219

221220
5. Output the buffer.
222221

223-
That is how our `IndentHandler`'s `Handle` method is structured:
222+
That is how `IndentHandler.Handle` is structured:
224223

225224
```
226225
func (h *IndentHandler) Handle(ctx context.Context, r slog.Record) error {
@@ -554,7 +553,7 @@ handler might look something like this:
554553
// ...
555554
}
556555

557-
A single handleWidgets request might generate hundreds of log lines.
556+
A single `handleWidgets` request might generate hundreds of log lines.
558557
For instance, it might contain code like this:
559558

560559
for _, w := range widgets {
@@ -728,7 +727,7 @@ func TestSlogtest(t *testing.T) {
728727
}
729728
```
730729

731-
Calling `TestHandler` is easy. The hard part is parsing the output.
730+
Calling `TestHandler` is easy. The hard part is parsing your handler's output.
732731
`TestHandler` calls your handler multiple times, resulting in a sequence of log
733732
entries.
734733
It is your job to parse each entry into a `map[string]any`.
@@ -851,8 +850,7 @@ like an invalid argument, is to panic or return an error.
851850
The built-in handlers do not follow that advice.
852851
Few things are more frustrating than being unable to debug a problem that
853852
causes logging to fail;
854-
our feeling is that it is
855-
better to produce some output, however imperfect, than to produce none at all.
853+
it is better to produce some output, however imperfect, than to produce none at all.
856854
That is why methods like `Logger.Info` convert programming bugs in their list of
857855
key-value pairs, like missing values or malformed keys,
858856
into `Attr`s that contain as much information as possible.
@@ -878,7 +876,7 @@ The most likely explanation for the issue is that a newer version of the `slog`
878876
a new `Kind`&mdash;a backwards-compatible change under the Go 1 Compatibility
879877
Promise&mdash;and the handler wasn't updated.
880878
That is certainly a problem, but it shouldn't deprive
881-
readers of the logs from seeing the rest of the output.
879+
readers from seeing the rest of the log output.
882880

883881
There is one circumstance where returning an error from `Handler.Handle` is appropriate.
884882
If the output operation itself fails, the best course of action is to report

slog-handler-guide/guide.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ such as gathering key-value pairs into `Attr`s, and then call one or more
3131
and the output methods.
3232

3333
An output method fulfills the main role of a logger: producing log output.
34-
Here is an example call to an output method:
34+
Here is a call to an output method:
3535

3636
logger.Info("hello", "key", value)
3737

@@ -56,7 +56,6 @@ A logger's `With` method calls its handler's `WithAttrs` method.
5656

5757
The `WithGroup` method is used to avoid avoid key collisions in large programs
5858
by establishing separate namespaces.
59-
6059
This call creates a new `Logger` value with a group named "g":
6160

6261
logger = logger.WithGroup("g")
@@ -102,8 +101,8 @@ and the `New` function that constructs it from an `io.Writer` and options:
102101

103102
We'll support only one option, the ability to set a minimum level in order to
104103
supress detailed log output.
105-
Handlers should always use the `slog.Leveler` type for this option.
106-
`Leveler` is implemented by both `Level` and `LevelVar`.
104+
Handlers should always declare this option to be a `slog.Leveler`.
105+
The `slog.Leveler` interface is implemented by both `Level` and `LevelVar`.
107106
A `Level` value is easy for the user to provide,
108107
but changing the level of multiple handlers requires tracking them all.
109108
If the user instead passes a `LevelVar`, then a single change to that `LevelVar`
@@ -178,7 +177,7 @@ groups established by `WithGroup`.
178177

179178
5. Output the buffer.
180179

181-
That is how our `IndentHandler`'s `Handle` method is structured:
180+
That is how `IndentHandler.Handle` is structured:
182181

183182
%include indenthandler1/indent_handler.go handle -
184183

@@ -373,7 +372,7 @@ handler might look something like this:
373372
// ...
374373
}
375374

376-
A single handleWidgets request might generate hundreds of log lines.
375+
A single `handleWidgets` request might generate hundreds of log lines.
377376
For instance, it might contain code like this:
378377

379378
for _, w := range widgets {
@@ -460,7 +459,7 @@ for our example handler:
460459

461460
%include indenthandler3/indent_handler_test.go TestSlogtest -
462461

463-
Calling `TestHandler` is easy. The hard part is parsing the output.
462+
Calling `TestHandler` is easy. The hard part is parsing your handler's output.
464463
`TestHandler` calls your handler multiple times, resulting in a sequence of log
465464
entries.
466465
It is your job to parse each entry into a `map[string]any`.
@@ -569,8 +568,7 @@ like an invalid argument, is to panic or return an error.
569568
The built-in handlers do not follow that advice.
570569
Few things are more frustrating than being unable to debug a problem that
571570
causes logging to fail;
572-
our feeling is that it is
573-
better to produce some output, however imperfect, than to produce none at all.
571+
it is better to produce some output, however imperfect, than to produce none at all.
574572
That is why methods like `Logger.Info` convert programming bugs in their list of
575573
key-value pairs, like missing values or malformed keys,
576574
into `Attr`s that contain as much information as possible.
@@ -596,7 +594,7 @@ The most likely explanation for the issue is that a newer version of the `slog`
596594
a new `Kind`&mdash;a backwards-compatible change under the Go 1 Compatibility
597595
Promise&mdash;and the handler wasn't updated.
598596
That is certainly a problem, but it shouldn't deprive
599-
readers of the logs from seeing the rest of the output.
597+
readers from seeing the rest of the log output.
600598

601599
There is one circumstance where returning an error from `Handler.Handle` is appropriate.
602600
If the output operation itself fails, the best course of action is to report

0 commit comments

Comments
 (0)