Skip to content

Commit 83e03c7

Browse files
authored
stop using deprecated io/ioutils package (#620) (#620)
1 parent bb14b8b commit 83e03c7

File tree

9 files changed

+28
-32
lines changed

9 files changed

+28
-32
lines changed

benchmark_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package zerolog
33
import (
44
"context"
55
"errors"
6-
"io/ioutil"
6+
"io"
77
"net"
88
"testing"
99
"time"
@@ -15,7 +15,7 @@ var (
1515
)
1616

1717
func BenchmarkLogEmpty(b *testing.B) {
18-
logger := New(ioutil.Discard)
18+
logger := New(io.Discard)
1919
b.ResetTimer()
2020
b.RunParallel(func(pb *testing.PB) {
2121
for pb.Next() {
@@ -25,7 +25,7 @@ func BenchmarkLogEmpty(b *testing.B) {
2525
}
2626

2727
func BenchmarkDisabled(b *testing.B) {
28-
logger := New(ioutil.Discard).Level(Disabled)
28+
logger := New(io.Discard).Level(Disabled)
2929
b.ResetTimer()
3030
b.RunParallel(func(pb *testing.PB) {
3131
for pb.Next() {
@@ -35,7 +35,7 @@ func BenchmarkDisabled(b *testing.B) {
3535
}
3636

3737
func BenchmarkInfo(b *testing.B) {
38-
logger := New(ioutil.Discard)
38+
logger := New(io.Discard)
3939
b.ResetTimer()
4040
b.RunParallel(func(pb *testing.PB) {
4141
for pb.Next() {
@@ -45,7 +45,7 @@ func BenchmarkInfo(b *testing.B) {
4545
}
4646

4747
func BenchmarkContextFields(b *testing.B) {
48-
logger := New(ioutil.Discard).With().
48+
logger := New(io.Discard).With().
4949
Str("string", "four!").
5050
Time("time", time.Time{}).
5151
Int("int", 123).
@@ -60,7 +60,7 @@ func BenchmarkContextFields(b *testing.B) {
6060
}
6161

6262
func BenchmarkContextAppend(b *testing.B) {
63-
logger := New(ioutil.Discard).With().
63+
logger := New(io.Discard).With().
6464
Str("foo", "bar").
6565
Logger()
6666
b.ResetTimer()
@@ -72,7 +72,7 @@ func BenchmarkContextAppend(b *testing.B) {
7272
}
7373

7474
func BenchmarkLogFields(b *testing.B) {
75-
logger := New(ioutil.Discard)
75+
logger := New(io.Discard)
7676
b.ResetTimer()
7777
b.RunParallel(func(pb *testing.PB) {
7878
for pb.Next() {
@@ -102,7 +102,7 @@ func BenchmarkLogArrayObject(b *testing.B) {
102102
obj1 := obj{"a", "b", 2}
103103
obj2 := obj{"c", "d", 3}
104104
obj3 := obj{"e", "f", 4}
105-
logger := New(ioutil.Discard)
105+
logger := New(io.Discard)
106106
b.ResetTimer()
107107
b.ReportAllocs()
108108
for i := 0; i < b.N; i++ {
@@ -224,7 +224,7 @@ func BenchmarkLogFieldType(b *testing.B) {
224224
return e.Object("k", objects[0])
225225
},
226226
}
227-
logger := New(ioutil.Discard)
227+
logger := New(io.Discard)
228228
b.ResetTimer()
229229
for name := range types {
230230
f := types[name]
@@ -358,7 +358,7 @@ func BenchmarkContextFieldType(b *testing.B) {
358358
return c.Timestamp()
359359
},
360360
}
361-
logger := New(ioutil.Discard)
361+
logger := New(io.Discard)
362362
b.ResetTimer()
363363
for name := range types {
364364
f := types[name]

binary_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99

10-
// "io/ioutil"
1110
stdlog "log"
1211
"time"
1312
)

console_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package zerolog_test
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"strings"
99
"testing"
@@ -474,7 +474,7 @@ func BenchmarkConsoleWriter(b *testing.B) {
474474

475475
var msg = []byte(`{"level": "info", "foo": "bar", "message": "HELLO", "time": "1990-01-01"}`)
476476

477-
w := zerolog.ConsoleWriter{Out: ioutil.Discard, NoColor: false}
477+
w := zerolog.ConsoleWriter{Out: io.Discard, NoColor: false}
478478

479479
for i := 0; i < b.N; i++ {
480480
w.Write(msg)

context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package zerolog
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"math"
88
"net"
99
"time"
@@ -57,7 +57,7 @@ func (c Context) Array(key string, arr LogArrayMarshaler) Context {
5757

5858
// Object marshals an object that implement the LogObjectMarshaler interface.
5959
func (c Context) Object(key string, obj LogObjectMarshaler) Context {
60-
e := newEvent(LevelWriterAdapter{ioutil.Discard}, 0)
60+
e := newEvent(LevelWriterAdapter{io.Discard}, 0)
6161
e.Object(key, obj)
6262
c.l.context = enc.AppendObjectData(c.l.context, e.buf)
6363
putEvent(e)
@@ -66,7 +66,7 @@ func (c Context) Object(key string, obj LogObjectMarshaler) Context {
6666

6767
// EmbedObject marshals and Embeds an object that implement the LogObjectMarshaler interface.
6868
func (c Context) EmbedObject(obj LogObjectMarshaler) Context {
69-
e := newEvent(LevelWriterAdapter{ioutil.Discard}, 0)
69+
e := newEvent(LevelWriterAdapter{io.Discard}, 0)
7070
e.EmbedObject(obj)
7171
c.l.context = enc.AppendObjectData(c.l.context, e.buf)
7272
putEvent(e)

ctx_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package zerolog
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"reflect"
77
"testing"
88
)
99

1010
func TestCtx(t *testing.T) {
11-
log := New(ioutil.Discard)
11+
log := New(io.Discard)
1212
ctx := log.WithContext(context.Background())
1313
log2 := Ctx(ctx)
1414
if !reflect.DeepEqual(log, *log2) {
@@ -37,13 +37,13 @@ func TestCtx(t *testing.T) {
3737
}
3838

3939
func TestCtxDisabled(t *testing.T) {
40-
dl := New(ioutil.Discard).Level(Disabled)
40+
dl := New(io.Discard).Level(Disabled)
4141
ctx := dl.WithContext(context.Background())
4242
if ctx != context.Background() {
4343
t.Error("WithContext stored a disabled logger")
4444
}
4545

46-
l := New(ioutil.Discard).With().Str("foo", "bar").Logger()
46+
l := New(io.Discard).With().Str("foo", "bar").Logger()
4747
ctx = l.WithContext(ctx)
4848
if !reflect.DeepEqual(Ctx(ctx), &l) {
4949
t.Error("WithContext did not store logger")

diode/diode_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package diode_test
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"log"
87
"os"
98
"testing"
@@ -39,15 +38,15 @@ func TestClose(t *testing.T) {
3938
}
4039

4140
func Benchmark(b *testing.B) {
42-
log.SetOutput(ioutil.Discard)
41+
log.SetOutput(io.Discard)
4342
defer log.SetOutput(os.Stderr)
4443
benchs := map[string]time.Duration{
4544
"Waiter": 0,
4645
"Pooler": 10 * time.Millisecond,
4746
}
4847
for name, interval := range benchs {
4948
b.Run(name, func(b *testing.B) {
50-
w := diode.NewWriter(ioutil.Discard, 100000, interval, nil)
49+
w := diode.NewWriter(io.Discard, 100000, interval, nil)
5150
log := zerolog.New(w)
5251
defer w.Close()
5352

hlog/hlog_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10-
"io/ioutil"
1110
"net/http"
1211
"net/http/httptest"
1312
"net/url"
@@ -333,10 +332,10 @@ func BenchmarkHandlers(b *testing.B) {
333332
}))
334333
h2 := MethodHandler("method")(RequestHandler("request")(h1))
335334
handlers := map[string]http.Handler{
336-
"Single": NewHandler(zerolog.New(ioutil.Discard))(h1),
337-
"Combined": NewHandler(zerolog.New(ioutil.Discard))(h2),
338-
"SingleDisabled": NewHandler(zerolog.New(ioutil.Discard).Level(zerolog.Disabled))(h1),
339-
"CombinedDisabled": NewHandler(zerolog.New(ioutil.Discard).Level(zerolog.Disabled))(h2),
335+
"Single": NewHandler(zerolog.New(io.Discard))(h1),
336+
"Combined": NewHandler(zerolog.New(io.Discard))(h2),
337+
"SingleDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h1),
338+
"CombinedDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h2),
340339
}
341340
for name := range handlers {
342341
h := handlers[name]

hook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package zerolog
33
import (
44
"bytes"
55
"context"
6-
"io/ioutil"
6+
"io"
77
"testing"
88
)
99

@@ -172,7 +172,7 @@ func TestHook(t *testing.T) {
172172
}
173173

174174
func BenchmarkHooks(b *testing.B) {
175-
logger := New(ioutil.Discard)
175+
logger := New(io.Discard)
176176
b.ResetTimer()
177177
b.Run("Nop/Single", func(b *testing.B) {
178178
log := logger.Hook(nopHook)

log.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ import (
118118
"errors"
119119
"fmt"
120120
"io"
121-
"io/ioutil"
122121
"os"
123122
"strconv"
124123
"strings"
@@ -246,7 +245,7 @@ type Logger struct {
246245
// you may consider using sync wrapper.
247246
func New(w io.Writer) Logger {
248247
if w == nil {
249-
w = ioutil.Discard
248+
w = io.Discard
250249
}
251250
lw, ok := w.(LevelWriter)
252251
if !ok {

0 commit comments

Comments
 (0)