Skip to content

Commit

Permalink
stop using deprecated io/ioutils package (#620) (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
kerolasa committed Nov 24, 2023
1 parent bb14b8b commit 83e03c7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
20 changes: 10 additions & 10 deletions benchmark_test.go
Expand Up @@ -3,7 +3,7 @@ package zerolog
import (
"context"
"errors"
"io/ioutil"
"io"
"net"
"testing"
"time"
Expand All @@ -15,7 +15,7 @@ var (
)

func BenchmarkLogEmpty(b *testing.B) {
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -25,7 +25,7 @@ func BenchmarkLogEmpty(b *testing.B) {
}

func BenchmarkDisabled(b *testing.B) {
logger := New(ioutil.Discard).Level(Disabled)
logger := New(io.Discard).Level(Disabled)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -35,7 +35,7 @@ func BenchmarkDisabled(b *testing.B) {
}

func BenchmarkInfo(b *testing.B) {
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -45,7 +45,7 @@ func BenchmarkInfo(b *testing.B) {
}

func BenchmarkContextFields(b *testing.B) {
logger := New(ioutil.Discard).With().
logger := New(io.Discard).With().
Str("string", "four!").
Time("time", time.Time{}).
Int("int", 123).
Expand All @@ -60,7 +60,7 @@ func BenchmarkContextFields(b *testing.B) {
}

func BenchmarkContextAppend(b *testing.B) {
logger := New(ioutil.Discard).With().
logger := New(io.Discard).With().
Str("foo", "bar").
Logger()
b.ResetTimer()
Expand All @@ -72,7 +72,7 @@ func BenchmarkContextAppend(b *testing.B) {
}

func BenchmarkLogFields(b *testing.B) {
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand Down Expand Up @@ -102,7 +102,7 @@ func BenchmarkLogArrayObject(b *testing.B) {
obj1 := obj{"a", "b", 2}
obj2 := obj{"c", "d", 3}
obj3 := obj{"e", "f", 4}
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -224,7 +224,7 @@ func BenchmarkLogFieldType(b *testing.B) {
return e.Object("k", objects[0])
},
}
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
for name := range types {
f := types[name]
Expand Down Expand Up @@ -358,7 +358,7 @@ func BenchmarkContextFieldType(b *testing.B) {
return c.Timestamp()
},
}
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
for name := range types {
f := types[name]
Expand Down
1 change: 0 additions & 1 deletion binary_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"

// "io/ioutil"
stdlog "log"
"time"
)
Expand Down
4 changes: 2 additions & 2 deletions console_test.go
Expand Up @@ -3,7 +3,7 @@ package zerolog_test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -474,7 +474,7 @@ func BenchmarkConsoleWriter(b *testing.B) {

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

w := zerolog.ConsoleWriter{Out: ioutil.Discard, NoColor: false}
w := zerolog.ConsoleWriter{Out: io.Discard, NoColor: false}

for i := 0; i < b.N; i++ {
w.Write(msg)
Expand Down
6 changes: 3 additions & 3 deletions context.go
Expand Up @@ -3,7 +3,7 @@ package zerolog
import (
"context"
"fmt"
"io/ioutil"
"io"
"math"
"net"
"time"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (c Context) Array(key string, arr LogArrayMarshaler) Context {

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

// EmbedObject marshals and Embeds an object that implement the LogObjectMarshaler interface.
func (c Context) EmbedObject(obj LogObjectMarshaler) Context {
e := newEvent(LevelWriterAdapter{ioutil.Discard}, 0)
e := newEvent(LevelWriterAdapter{io.Discard}, 0)
e.EmbedObject(obj)
c.l.context = enc.AppendObjectData(c.l.context, e.buf)
putEvent(e)
Expand Down
8 changes: 4 additions & 4 deletions ctx_test.go
Expand Up @@ -2,13 +2,13 @@ package zerolog

import (
"context"
"io/ioutil"
"io"
"reflect"
"testing"
)

func TestCtx(t *testing.T) {
log := New(ioutil.Discard)
log := New(io.Discard)
ctx := log.WithContext(context.Background())
log2 := Ctx(ctx)
if !reflect.DeepEqual(log, *log2) {
Expand Down Expand Up @@ -37,13 +37,13 @@ func TestCtx(t *testing.T) {
}

func TestCtxDisabled(t *testing.T) {
dl := New(ioutil.Discard).Level(Disabled)
dl := New(io.Discard).Level(Disabled)
ctx := dl.WithContext(context.Background())
if ctx != context.Background() {
t.Error("WithContext stored a disabled logger")
}

l := New(ioutil.Discard).With().Str("foo", "bar").Logger()
l := New(io.Discard).With().Str("foo", "bar").Logger()
ctx = l.WithContext(ctx)
if !reflect.DeepEqual(Ctx(ctx), &l) {
t.Error("WithContext did not store logger")
Expand Down
5 changes: 2 additions & 3 deletions diode/diode_test.go
Expand Up @@ -3,7 +3,6 @@ package diode_test
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"testing"
Expand Down Expand Up @@ -39,15 +38,15 @@ func TestClose(t *testing.T) {
}

func Benchmark(b *testing.B) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

Check failure on line 41 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 41 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 41 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 41 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 41 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
defer log.SetOutput(os.Stderr)
benchs := map[string]time.Duration{
"Waiter": 0,
"Pooler": 10 * time.Millisecond,
}
for name, interval := range benchs {
b.Run(name, func(b *testing.B) {
w := diode.NewWriter(ioutil.Discard, 100000, interval, nil)
w := diode.NewWriter(io.Discard, 100000, interval, nil)

Check failure on line 49 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 49 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 49 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 49 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 49 in diode/diode_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
log := zerolog.New(w)
defer w.Close()

Expand Down
9 changes: 4 additions & 5 deletions hlog/hlog_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -333,10 +332,10 @@ func BenchmarkHandlers(b *testing.B) {
}))
h2 := MethodHandler("method")(RequestHandler("request")(h1))
handlers := map[string]http.Handler{
"Single": NewHandler(zerolog.New(ioutil.Discard))(h1),
"Combined": NewHandler(zerolog.New(ioutil.Discard))(h2),
"SingleDisabled": NewHandler(zerolog.New(ioutil.Discard).Level(zerolog.Disabled))(h1),
"CombinedDisabled": NewHandler(zerolog.New(ioutil.Discard).Level(zerolog.Disabled))(h2),
"Single": NewHandler(zerolog.New(io.Discard))(h1),

Check failure on line 335 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 335 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 335 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 335 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 335 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
"Combined": NewHandler(zerolog.New(io.Discard))(h2),

Check failure on line 336 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 336 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 336 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 336 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 336 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
"SingleDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h1),

Check failure on line 337 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 337 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 337 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 337 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 337 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
"CombinedDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h2),

Check failure on line 338 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: io

Check failure on line 338 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

undefined: io

Check failure on line 338 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, macos-latest)

undefined: io

Check failure on line 338 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: io

Check failure on line 338 in hlog/hlog_test.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: io
}
for name := range handlers {
h := handlers[name]
Expand Down
4 changes: 2 additions & 2 deletions hook_test.go
Expand Up @@ -3,7 +3,7 @@ package zerolog
import (
"bytes"
"context"
"io/ioutil"
"io"
"testing"
)

Expand Down Expand Up @@ -172,7 +172,7 @@ func TestHook(t *testing.T) {
}

func BenchmarkHooks(b *testing.B) {
logger := New(ioutil.Discard)
logger := New(io.Discard)
b.ResetTimer()
b.Run("Nop/Single", func(b *testing.B) {
log := logger.Hook(nopHook)
Expand Down
3 changes: 1 addition & 2 deletions log.go
Expand Up @@ -118,7 +118,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -246,7 +245,7 @@ type Logger struct {
// you may consider using sync wrapper.
func New(w io.Writer) Logger {
if w == nil {
w = ioutil.Discard
w = io.Discard
}
lw, ok := w.(LevelWriter)
if !ok {
Expand Down

0 comments on commit 83e03c7

Please sign in to comment.