mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
log instead of fmt
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
package dnstapio
|
package dnstapio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
// DnstapIO wraps the dnstap I/O routine.
|
// DnstapIO wraps the dnstap I/O routine.
|
||||||
type DnstapIO struct {
|
type DnstapIO struct {
|
||||||
iolog io.Writer
|
|
||||||
writer io.WriteCloser
|
writer io.WriteCloser
|
||||||
queue chan tap.Dnstap
|
queue chan tap.Dnstap
|
||||||
stop chan bool
|
stop chan bool
|
||||||
@@ -27,7 +30,7 @@ type Protocol interface {
|
|||||||
|
|
||||||
// New dnstap I/O routine from Protocol.
|
// New dnstap I/O routine from Protocol.
|
||||||
func New(w Protocol) *DnstapIO {
|
func New(w Protocol) *DnstapIO {
|
||||||
dio := DnstapIO{iolog: os.Stdout}
|
dio := DnstapIO{}
|
||||||
dio.writer = w
|
dio.writer = w
|
||||||
dio.queue = make(chan tap.Dnstap, 10)
|
dio.queue = make(chan tap.Dnstap, 10)
|
||||||
dio.stop = make(chan bool)
|
dio.stop = make(chan bool)
|
||||||
@@ -40,7 +43,7 @@ func (dio *DnstapIO) Dnstap(payload tap.Dnstap) {
|
|||||||
select {
|
select {
|
||||||
case dio.queue <- payload:
|
case dio.queue <- payload:
|
||||||
default:
|
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 {
|
if err == nil {
|
||||||
dio.writer.Write(frame)
|
dio.writer.Write(frame)
|
||||||
} else {
|
} 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:
|
case <-dio.stop:
|
||||||
close(dio.queue)
|
close(dio.queue)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package dnstapio
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -10,6 +11,10 @@ import (
|
|||||||
tap "github.com/dnstap/golang-dnstap"
|
tap "github.com/dnstap/golang-dnstap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetOutput(ioutil.Discard)
|
||||||
|
}
|
||||||
|
|
||||||
type buf struct {
|
type buf struct {
|
||||||
*bytes.Buffer
|
*bytes.Buffer
|
||||||
cost time.Duration
|
cost time.Duration
|
||||||
@@ -27,7 +32,6 @@ func (b buf) Close() error {
|
|||||||
func TestRace(t *testing.T) {
|
func TestRace(t *testing.T) {
|
||||||
b := buf{&bytes.Buffer{}, 100 * time.Millisecond}
|
b := buf{&bytes.Buffer{}, 100 * time.Millisecond}
|
||||||
dio := New(b)
|
dio := New(b)
|
||||||
dio.iolog = ioutil.Discard // don't flood Travis
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(10)
|
wg.Add(10)
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user