@@ -31,7 +31,7 @@ such as gathering key-value pairs into `Attr`s, and then call one or more
31
31
and the output methods.
32
32
33
33
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:
35
35
36
36
logger.Info("hello", "key", value)
37
37
@@ -56,7 +56,6 @@ A logger's `With` method calls its handler's `WithAttrs` method.
56
56
57
57
The ` WithGroup ` method is used to avoid avoid key collisions in large programs
58
58
by establishing separate namespaces.
59
-
60
59
This call creates a new ` Logger ` value with a group named "g":
61
60
62
61
logger = logger.WithGroup("g")
@@ -102,8 +101,8 @@ and the `New` function that constructs it from an `io.Writer` and options:
102
101
103
102
We'll support only one option, the ability to set a minimum level in order to
104
103
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 ` .
107
106
A ` Level ` value is easy for the user to provide,
108
107
but changing the level of multiple handlers requires tracking them all.
109
108
If the user instead passes a ` LevelVar ` , then a single change to that ` LevelVar `
@@ -178,7 +177,7 @@ groups established by `WithGroup`.
178
177
179
178
5 . Output the buffer.
180
179
181
- That is how our ` IndentHandler ` 's ` Handle ` method is structured:
180
+ That is how ` IndentHandler. Handle ` is structured:
182
181
183
182
%include indenthandler1/indent_handler.go handle -
184
183
@@ -373,7 +372,7 @@ handler might look something like this:
373
372
// ...
374
373
}
375
374
376
- A single handleWidgets request might generate hundreds of log lines.
375
+ A single ` handleWidgets ` request might generate hundreds of log lines.
377
376
For instance, it might contain code like this:
378
377
379
378
for _, w := range widgets {
@@ -460,7 +459,7 @@ for our example handler:
460
459
461
460
%include indenthandler3/indent_handler_test.go TestSlogtest -
462
461
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.
464
463
` TestHandler ` calls your handler multiple times, resulting in a sequence of log
465
464
entries.
466
465
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.
569
568
The built-in handlers do not follow that advice.
570
569
Few things are more frustrating than being unable to debug a problem that
571
570
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.
574
572
That is why methods like ` Logger.Info ` convert programming bugs in their list of
575
573
key-value pairs, like missing values or malformed keys,
576
574
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`
596
594
a new ` Kind ` &mdash ; a backwards-compatible change under the Go 1 Compatibility
597
595
Promise&mdash ; and the handler wasn't updated.
598
596
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.
600
598
601
599
There is one circumstance where returning an error from ` Handler.Handle ` is appropriate.
602
600
If the output operation itself fails, the best course of action is to report
0 commit comments