Skip to content

Commit b61f268

Browse files
authored
Merge pull request #1472 from goldlinker/master
refactor: replace the deprecated function in the ioutil package
2 parents cb253f3 + 15c29db commit b61f268

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

alt_exit_test.go

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

33
import (
4-
"io/ioutil"
54
"log"
65
"os"
76
"os/exec"
@@ -76,14 +75,14 @@ func TestHandler(t *testing.T) {
7675
testprog := testprogleader
7776
testprog = append(testprog, getPackage()...)
7877
testprog = append(testprog, testprogtrailer...)
79-
tempDir, err := ioutil.TempDir("", "test_handler")
78+
tempDir, err := os.MkdirTemp("", "test_handler")
8079
if err != nil {
8180
log.Fatalf("can't create temp dir. %q", err)
8281
}
8382
defer os.RemoveAll(tempDir)
8483

8584
gofile := filepath.Join(tempDir, "gofile.go")
86-
if err := ioutil.WriteFile(gofile, testprog, 0666); err != nil {
85+
if err := os.WriteFile(gofile, testprog, 0666); err != nil {
8786
t.Fatalf("can't create go file. %q", err)
8887
}
8988

@@ -94,7 +93,7 @@ func TestHandler(t *testing.T) {
9493
t.Fatalf("completed normally, should have failed")
9594
}
9695

97-
data, err := ioutil.ReadFile(outfile)
96+
data, err := os.ReadFile(outfile)
9897
if err != nil {
9998
t.Fatalf("can't read output file %s. %q", outfile, err)
10099
}

hooks/test/test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package test
44

55
import (
6-
"io/ioutil"
6+
"io"
77
"sync"
88

99
"github.com/sirupsen/logrus"
@@ -42,7 +42,7 @@ func NewLocal(logger *logrus.Logger) *Hook {
4242
func NewNullLogger() (*logrus.Logger, *Hook) {
4343

4444
logger := logrus.New()
45-
logger.Out = ioutil.Discard
45+
logger.Out = io.Discard
4646

4747
return logger, NewLocal(logger)
4848

hooks/writer/writer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package writer
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"testing"
77

88
log "github.com/sirupsen/logrus"
@@ -16,7 +16,7 @@ func TestDifferentLevelsGoToDifferentWriters(t *testing.T) {
1616
DisableTimestamp: true,
1717
DisableColors: true,
1818
})
19-
log.SetOutput(ioutil.Discard) // Send all logs to nowhere by default
19+
log.SetOutput(io.Discard) // Send all logs to nowhere by default
2020

2121
log.AddHook(&Hook{
2222
Writer: &a,

logger_bench_test.go

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

33
import (
4-
"io/ioutil"
4+
"io"
55
"os"
66
"testing"
77
)
@@ -65,7 +65,7 @@ func doLoggerBenchmarkWithFormatter(b *testing.B, f Formatter) {
6565
b.SetParallelism(100)
6666
log := New()
6767
log.Formatter = f
68-
log.Out = ioutil.Discard
68+
log.Out = io.Discard
6969
b.RunParallel(func(pb *testing.PB) {
7070
for pb.Next() {
7171
log.

logrus_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"path/filepath"
1010
"runtime"
@@ -636,7 +636,7 @@ func TestReplaceHooks(t *testing.T) {
636636
old, cur := &TestHook{}, &TestHook{}
637637

638638
logger := New()
639-
logger.SetOutput(ioutil.Discard)
639+
logger.SetOutput(io.Discard)
640640
logger.AddHook(old)
641641

642642
hooks := make(LevelHooks)
@@ -781,7 +781,7 @@ func TestReportCallerOnTextFormatter(t *testing.T) {
781781

782782
func TestSetReportCallerRace(t *testing.T) {
783783
l := New()
784-
l.Out = ioutil.Discard
784+
l.Out = io.Discard
785785
l.SetReportCaller(true)
786786

787787
var wg sync.WaitGroup

0 commit comments

Comments
 (0)