From 88f09c39390e97c8f3a1f070aefee66fdf87ae48 Mon Sep 17 00:00:00 2001 From: varyoo Date: Fri, 29 Sep 2017 15:57:42 +0200 Subject: [PATCH] log instead of fmt --- plugin/dnstap/dnstapio/io.go | 13 ++++++++----- plugin/dnstap/dnstapio/io_test.go | 6 +++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/dnstap/dnstapio/io.go b/plugin/dnstap/dnstapio/io.go index ae7a39eed..c2b87ee78 100644 --- a/plugin/dnstap/dnstapio/io.go +++ b/plugin/dnstap/dnstapio/io.go @@ -1,17 +1,20 @@ package dnstapio import ( - "fmt" "io" + "log" "os" tap "github.com/dnstap/golang-dnstap" "github.com/golang/protobuf/proto" ) +func init() { + log.SetOutput(os.Stdout) +} + // DnstapIO wraps the dnstap I/O routine. type DnstapIO struct { - iolog io.Writer writer io.WriteCloser queue chan tap.Dnstap stop chan bool @@ -27,7 +30,7 @@ type Protocol interface { // New dnstap I/O routine from Protocol. func New(w Protocol) *DnstapIO { - dio := DnstapIO{iolog: os.Stdout} + dio := DnstapIO{} dio.writer = w dio.queue = make(chan tap.Dnstap, 10) dio.stop = make(chan bool) @@ -40,7 +43,7 @@ func (dio *DnstapIO) Dnstap(payload tap.Dnstap) { select { case dio.queue <- payload: default: - fmt.Fprintln(dio.iolog, "[WARN] Dnstap payload dropped.") + log.Println("[WARN] Dnstap payload dropped.") } } @@ -52,7 +55,7 @@ func (dio *DnstapIO) serve() { if err == nil { dio.writer.Write(frame) } else { - fmt.Fprintf(dio.iolog, "[ERROR] Invalid dnstap payload dropped: %s\n", err) + log.Printf("[ERROR] Invalid dnstap payload dropped: %s\n", err) } case <-dio.stop: close(dio.queue) diff --git a/plugin/dnstap/dnstapio/io_test.go b/plugin/dnstap/dnstapio/io_test.go index 82fa0b26f..17e7758c3 100644 --- a/plugin/dnstap/dnstapio/io_test.go +++ b/plugin/dnstap/dnstapio/io_test.go @@ -3,6 +3,7 @@ package dnstapio import ( "bytes" "io/ioutil" + "log" "sync" "testing" "time" @@ -10,6 +11,10 @@ import ( tap "github.com/dnstap/golang-dnstap" ) +func init() { + log.SetOutput(ioutil.Discard) +} + type buf struct { *bytes.Buffer cost time.Duration @@ -27,7 +32,6 @@ func (b buf) Close() error { func TestRace(t *testing.T) { b := buf{&bytes.Buffer{}, 100 * time.Millisecond} dio := New(b) - dio.iolog = ioutil.Discard // don't flood Travis wg := &sync.WaitGroup{} wg.Add(10) for i := 0; i < 10; i++ {