Skip to content

Commit c53c4ed

Browse files
committed
Update docs for V5
1 parent c036899 commit c53c4ed

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ Here is a list of reasons how we improved on zap with slog.
9292

9393
1. Simple and easy to extend
9494
- A new backend only has to implement the simple Sink interface.
95+
- The logger type provides a nice API around Sink and itself implements
96+
Sink allowing for composition and wrapping. E.g. one could implement
97+
a Sink that wraps around another sink to ensure no logs with a given
98+
component are logged.
9599
- zap is hard and confusing to extend. There are too many structures and configuration options.
96100

97101
1. Structured logging of Go structures with `json.Marshal`

internal/syncwriter/syncwriter_test.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package syncwriter
22

33
import (
4-
"bytes"
54
"io"
65
"os"
76
"testing"
@@ -39,12 +38,17 @@ func TestWriter_Sync(t *testing.T) {
3938
t.Parallel()
4039

4140
tw := newWriter(syncWriter{
42-
sw: func() error {
41+
wf: func([]byte) (int, error) {
42+
return 0, io.EOF
43+
},
44+
sf: func() error {
4345
return io.EOF
4446
},
4547
})
46-
tw.w.Sync("test")
48+
tw.w.Write("hello", nil)
4749
assert.Equal(t, 1, tw.errors, "errors")
50+
tw.w.Sync("test")
51+
assert.Equal(t, 2, tw.errors, "errors")
4852
})
4953

5054
t.Run("stdout", func(t *testing.T) {
@@ -54,6 +58,20 @@ func TestWriter_Sync(t *testing.T) {
5458
tw.w.Sync("test")
5559
assert.Equal(t, 0, tw.errors, "errors")
5660
})
61+
62+
t.Run("errorf", func(t *testing.T) {
63+
t.Parallel()
64+
65+
sw := New(syncWriter{
66+
wf: func([]byte) (int, error) {
67+
return 0, io.EOF
68+
},
69+
sf: func() error {
70+
return io.EOF
71+
},
72+
})
73+
sw.Write("hello", nil)
74+
})
5775
}
5876

5977
func Test_errorsIsAny(t *testing.T) {
@@ -64,12 +82,16 @@ func Test_errorsIsAny(t *testing.T) {
6482
}
6583

6684
type syncWriter struct {
67-
*bytes.Buffer
68-
sw func() error
85+
wf func([]byte) (int, error)
86+
sf func() error
6987
}
7088

7189
var _ syncer = &syncWriter{}
7290

91+
func (sw syncWriter) Write(p []byte) (int, error) {
92+
return sw.wf(p)
93+
}
94+
7395
func (sw syncWriter) Sync() error {
74-
return sw.sw()
96+
return sw.sf()
7597
}

0 commit comments

Comments
 (0)