Skip to content

Commit 6d5c5ef

Browse files
committed
Update examples
1 parent bbf7cfa commit 6d5c5ef

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ go get cdr.dev/slog
3535
Many more examples available at [godoc](https://godoc.org/cdr.dev/slog#pkg-examples).
3636

3737
```go
38-
slogtest.Info(t, "my message here",
38+
log := sloghuman.Make(os.Stdout)
39+
40+
log.Info(context.Background(), "my message here",
3941
slog.F("field_name", "something or the other"),
4042
slog.F("some_map", slog.M(
4143
slog.F("nested_fields", "wowow"),
@@ -50,7 +52,7 @@ slogtest.Info(t, "my message here",
5052
)
5153
```
5254

53-
![Example output screenshot](https://i.imgur.com/o8uW4Oy.png)
55+
![Example output screenshot](https://i.imgur.com/IkpYq2u.png)
5456

5557
## Why?
5658

example_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ import (
1616
)
1717

1818
func Example() {
19+
log := sloghuman.Make(os.Stdout)
20+
21+
log.Info(context.Background(), "my message here",
22+
slog.F("field_name", "something or the other"),
23+
slog.F("some_map", slog.M(
24+
slog.F("nested_fields", "wowow"),
25+
)),
26+
slog.Error(
27+
xerrors.Errorf("wrap1: %w",
28+
xerrors.Errorf("wrap2: %w",
29+
io.EOF,
30+
),
31+
),
32+
),
33+
)
34+
35+
// 2019-12-09 05:04:53.398 [INFO] <example.go:16> my message here {"field_name": "something or the other", "some_map": {"nested_fields": "wowow"}} ...
36+
// "error": wrap1:
37+
// main.main
38+
// /Users/nhooyr/src/cdr/scratch/example.go:22
39+
// - wrap2:
40+
// main.main
41+
// /Users/nhooyr/src/cdr/scratch/example.go:23
42+
// - EOF
43+
}
44+
45+
func Example_testing() {
1946
// Provided by the testing package in tests.
2047
var t testing.TB
2148

internal/assert/assert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NotEqual(t testing.TB, exp, act interface{}, name string) {
2424
}
2525
}
2626

27-
// Success asserts exp == nil.
27+
// Success asserts err == nil.
2828
func Success(t testing.TB, err error, name string) {
2929
t.Helper()
3030
if err != nil {

sloggers/sloghuman/sloghuman.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
// it will be called when syncing.
2222
func Make(w io.Writer) slog.Logger {
2323
return slog.Make(&humanSink{
24-
w: syncwriter.New(w),
24+
w: syncwriter.New(w),
25+
w2: w,
2526
})
2627
}
2728

0 commit comments

Comments
 (0)