Update all plugins to use plugin/pkg/log (#1694)

* Update all plugins to use plugin/pkg/log

I wish this could have been done with sed. Alas manually changed all
callers to use the new plugin/pkg/log package.

* Error -> Info

* Add docs to debug plugin as well
This commit is contained in:
Miek Gieben 2018-04-19 07:41:56 +01:00 committed by GitHub
parent 2095eb7979
commit 26d1432ae6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 101 additions and 132 deletions

View file

@ -1,7 +1,6 @@
package auto package auto
import ( import (
"log"
"os" "os"
"path" "path"
"regexp" "regexp"
@ -11,6 +10,7 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics" "github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/parse"
"github.com/coredns/coredns/plugin/pkg/upstream" "github.com/coredns/coredns/plugin/pkg/upstream"
@ -108,7 +108,7 @@ func autoParse(c *caddy.Controller) (Auto, error) {
_, err := os.Stat(a.loader.directory) _, err := os.Stat(a.loader.directory)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Printf("[WARNING] Directory does not exist: %s", a.loader.directory) log.Warningf("Directory does not exist: %s", a.loader.directory)
} else { } else {
return a, c.Errf("Unable to access root path '%s': %v", a.loader.directory, err) return a, c.Errf("Unable to access root path '%s': %v", a.loader.directory, err)
} }

View file

@ -1,13 +1,13 @@
package auto package auto
import ( import (
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"github.com/coredns/coredns/plugin/file" "github.com/coredns/coredns/plugin/file"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -40,7 +40,7 @@ func (a Auto) Walk() error {
reader, err := os.Open(path) reader, err := os.Open(path)
if err != nil { if err != nil {
log.Printf("[WARNING] Opening %s failed: %s", path, err) log.Warningf("Opening %s failed: %s", path, err)
return nil return nil
} }
defer reader.Close() defer reader.Close()
@ -48,7 +48,7 @@ func (a Auto) Walk() error {
// Serial for loading a zone is 0, because it is a new zone. // Serial for loading a zone is 0, because it is a new zone.
zo, err := file.Parse(reader, origin, path, 0) zo, err := file.Parse(reader, origin, path, 0)
if err != nil { if err != nil {
log.Printf("[WARNING] Parse zone `%s': %v", origin, err) log.Warningf("Parse zone `%s': %v", origin, err)
return nil return nil
} }
@ -64,7 +64,7 @@ func (a Auto) Walk() error {
zo.Notify() zo.Notify()
log.Printf("[INFO] Inserting zone `%s' from: %s", origin, path) log.Infof("Inserting zone `%s' from: %s", origin, path)
toDelete[origin] = false toDelete[origin] = false
@ -82,7 +82,7 @@ func (a Auto) Walk() error {
a.Zones.Remove(origin) a.Zones.Remove(origin)
log.Printf("[INFO] Deleting zone `%s'", origin) log.Infof("Deleting zone `%s'", origin)
} }
return nil return nil

View file

@ -2,7 +2,6 @@ package auto
import ( import (
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path" "path"
"regexp" "regexp"
@ -20,8 +19,6 @@ www IN A 127.0.0.1
` `
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {
log.SetOutput(ioutil.Discard)
tempdir, err := createFiles() tempdir, err := createFiles()
if err != nil { if err != nil {
if tempdir != "" { if tempdir != "" {
@ -53,8 +50,6 @@ func TestWalk(t *testing.T) {
} }
func TestWalkNonExistent(t *testing.T) { func TestWalkNonExistent(t *testing.T) {
log.SetOutput(ioutil.Discard)
nonExistingDir := "highly_unlikely_to_exist_dir" nonExistingDir := "highly_unlikely_to_exist_dir"
ldr := loader{ ldr := loader{

View file

@ -1,8 +1,6 @@
package auto package auto
import ( import (
"io/ioutil"
"log"
"os" "os"
"path" "path"
"regexp" "regexp"
@ -10,8 +8,6 @@ import (
) )
func TestWatcher(t *testing.T) { func TestWatcher(t *testing.T) {
log.SetOutput(ioutil.Discard)
tempdir, err := createFiles() tempdir, err := createFiles()
if err != nil { if err != nil {
if tempdir != "" { if tempdir != "" {

View file

@ -4,11 +4,11 @@ package cache
import ( import (
"encoding/binary" "encoding/binary"
"hash/fnv" "hash/fnv"
"log"
"time" "time"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/cache" "github.com/coredns/coredns/plugin/pkg/cache"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/response" "github.com/coredns/coredns/plugin/pkg/response"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
@ -178,13 +178,13 @@ func (w *ResponseWriter) set(m *dns.Msg, key int, mt response.Type, duration tim
case response.OtherError: case response.OtherError:
// don't cache these // don't cache these
default: default:
log.Printf("[WARNING] Caching called with unknown classification: %d", mt) log.Warningf("Caching called with unknown classification: %d", mt)
} }
} }
// Write implements the dns.ResponseWriter interface. // Write implements the dns.ResponseWriter interface.
func (w *ResponseWriter) Write(buf []byte) (int, error) { func (w *ResponseWriter) Write(buf []byte) (int, error) {
log.Print("[WARNING] Caching called with Write: not caching reply") log.Warning("Caching called with Write: not caching reply")
if w.prefetch { if w.prefetch {
return 0, nil return 0, nil
} }

View file

@ -1,8 +1,6 @@
package cache package cache
import ( import (
"io/ioutil"
"log"
"testing" "testing"
"time" "time"
@ -162,8 +160,6 @@ func TestCache(t *testing.T) {
c, crr := newTestCache(maxTTL) c, crr := newTestCache(maxTTL)
log.SetOutput(ioutil.Discard)
for _, tc := range cacheTestCases { for _, tc := range cacheTestCases {
m := tc.in.Msg() m := tc.in.Msg()
m = cacheMsg(m, tc) m = cacheMsg(m, tc)

View file

@ -7,7 +7,8 @@
## Description ## Description
Normally CoreDNS will recover from panics, using *debug* inhibits this. The main use of *debug* is Normally CoreDNS will recover from panics, using *debug* inhibits this. The main use of *debug* is
to help testing. to help testing. A side effect of using *debug* is that `log.Debug` and `log.Debugf` will be printed
to standard output.
Note that the *errors* plugin (if loaded) will also set a `recover` negating this setting. Note that the *errors* plugin (if loaded) will also set a `recover` negating this setting.
@ -19,7 +20,7 @@ debug
## Examples ## Examples
Disable the ability to recover from crashes: Disable the ability to recover from crashes and show debug logging:
~~~ corefile ~~~ corefile
. { . {

View file

@ -1,8 +1,6 @@
package debug package debug
import ( import (
"io/ioutil"
"log"
"testing" "testing"
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
@ -11,8 +9,6 @@ import (
) )
func TestDebug(t *testing.T) { func TestDebug(t *testing.T) {
log.SetOutput(ioutil.Discard)
tests := []struct { tests := []struct {
input string input string
shouldErr bool shouldErr bool

View file

@ -1,10 +1,10 @@
package dnssec package dnssec
import ( import (
"log"
"time" "time"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -40,7 +40,7 @@ func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
// Write implements the dns.ResponseWriter interface. // Write implements the dns.ResponseWriter interface.
func (d *ResponseWriter) Write(buf []byte) (int, error) { func (d *ResponseWriter) Write(buf []byte) (int, error) {
log.Print("[WARNING] Dnssec called with Write: not signing reply") log.Warning("Dnssec called with Write: not signing reply")
n, err := d.ResponseWriter.Write(buf) n, err := d.ResponseWriter.Write(buf)
return n, err return n, err
} }

View file

@ -1,11 +1,12 @@
package dnstapio package dnstapio
import ( import (
"log"
"net" "net"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
tap "github.com/dnstap/golang-dnstap" tap "github.com/dnstap/golang-dnstap"
fs "github.com/farsightsec/golang-framestream" fs "github.com/farsightsec/golang-framestream"
) )
@ -70,7 +71,7 @@ func (dio *dnstapIO) newConnect() error {
// Connect connects to the dnstop endpoint. // Connect connects to the dnstop endpoint.
func (dio *dnstapIO) Connect() { func (dio *dnstapIO) Connect() {
if err := dio.newConnect(); err != nil { if err := dio.newConnect(); err != nil {
log.Print("[ERROR] No connection to dnstap endpoint") log.Error("No connection to dnstap endpoint")
} }
go dio.serve() go dio.serve()
} }
@ -102,16 +103,16 @@ func (dio *dnstapIO) flushBuffer() {
if err := dio.newConnect(); err != nil { if err := dio.newConnect(); err != nil {
return return
} }
log.Print("[INFO] Reconnected to dnstap") log.Info("Reconnected to dnstap")
} }
if err := dio.enc.flushBuffer(); err != nil { if err := dio.enc.flushBuffer(); err != nil {
log.Printf("[WARN] Connection lost: %s", err) log.Warningf("Connection lost: %s", err)
dio.closeConnection() dio.closeConnection()
if err := dio.newConnect(); err != nil { if err := dio.newConnect(); err != nil {
log.Printf("[ERROR] Cannot connect to dnstap: %s", err) log.Errorf("Cannot connect to dnstap: %s", err)
} else { } else {
log.Print("[INFO] Reconnected to dnstap") log.Info("Reconnected to dnstap")
} }
} }
} }
@ -134,7 +135,7 @@ func (dio *dnstapIO) serve() {
dio.write(&payload) dio.write(&payload)
case <-timeout: case <-timeout:
if dropped := atomic.SwapUint32(&dio.dropped, 0); dropped > 0 { if dropped := atomic.SwapUint32(&dio.dropped, 0); dropped > 0 {
log.Printf("[WARN] Dropped dnstap messages: %d", dropped) log.Warningf("Dropped dnstap messages: %d", dropped)
} }
dio.flushBuffer() dio.flushBuffer()
timeout = time.After(flushTimeout) timeout = time.After(flushTimeout)

View file

@ -1,13 +1,13 @@
package etcd package etcd
import ( import (
"log"
"net" "net"
"strconv" "strconv"
"time" "time"
"github.com/coredns/coredns/plugin/etcd/msg" "github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/dnsutil" "github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/proxy" "github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
@ -50,7 +50,7 @@ Services:
} }
ip := net.ParseIP(serv.Host) ip := net.ParseIP(serv.Host)
if ip == nil { if ip == nil {
log.Printf("[WARNING] Non IP address stub nameserver: %s", serv.Host) log.Warningf("Non IP address stub nameserver: %s", serv.Host)
continue continue
} }
@ -64,7 +64,7 @@ Services:
// We must *also* chop of dns.stub. which means cutting two more labels. // We must *also* chop of dns.stub. which means cutting two more labels.
domain = dnsutil.Join(labels[1 : len(labels)-dns.CountLabel(z)-2]) domain = dnsutil.Join(labels[1 : len(labels)-dns.CountLabel(z)-2])
if domain == z { if domain == z {
log.Printf("[WARNING] Skipping nameserver for domain we are authoritative for: %s", domain) log.Warningf("Skipping nameserver for domain we are authoritative for: %s", domain)
continue Services continue Services
} }
} }

View file

@ -2,8 +2,8 @@ package etcd
import ( import (
"errors" "errors"
"log"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -19,7 +19,7 @@ type Stub struct {
// ServeDNS implements the plugin.Handler interface. // ServeDNS implements the plugin.Handler interface.
func (s Stub) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.Msg) (int, error) { func (s Stub) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.Msg) (int, error) {
if hasStubEdns0(req) { if hasStubEdns0(req) {
log.Printf("[WARNING] Forwarding cycle detected, refusing msg: %s", req.Question[0].Name) log.Warningf("Forwarding cycle detected, refusing msg: %s", req.Question[0].Name)
return dns.RcodeRefused, errors.New("stub forward cycle") return dns.RcodeRefused, errors.New("stub forward cycle")
} }
req = addStubEdns0(req) req = addStubEdns0(req)

View file

@ -4,9 +4,9 @@ package file
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -52,24 +52,24 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
state.SizeAndDo(m) state.SizeAndDo(m)
w.WriteMsg(m) w.WriteMsg(m)
log.Printf("[INFO] Notify from %s for %s: checking transfer", state.IP(), zone) log.Infof("Notify from %s for %s: checking transfer", state.IP(), zone)
ok, err := z.shouldTransfer() ok, err := z.shouldTransfer()
if ok { if ok {
z.TransferIn() z.TransferIn()
} else { } else {
log.Printf("[INFO] Notify from %s for %s: no serial increase seen", state.IP(), zone) log.Infof("Notify from %s for %s: no serial increase seen", state.IP(), zone)
} }
if err != nil { if err != nil {
log.Printf("[WARNING] Notify from %s for %s: failed primary check: %s", state.IP(), zone, err) log.Warningf("Notify from %s for %s: failed primary check: %s", state.IP(), zone, err)
} }
return dns.RcodeSuccess, nil return dns.RcodeSuccess, nil
} }
log.Printf("[INFO] Dropping notify from %s for %s", state.IP(), zone) log.Infof("Dropping notify from %s for %s", state.IP(), zone)
return dns.RcodeSuccess, nil return dns.RcodeSuccess, nil
} }
if z.Expired != nil && *z.Expired { if z.Expired != nil && *z.Expired {
log.Printf("[ERROR] Zone %s is expired", zone) log.Errorf("Zone %s is expired", zone)
return dns.RcodeServerFailure, nil return dns.RcodeServerFailure, nil
} }

View file

@ -2,9 +2,9 @@ package file
import ( import (
"fmt" "fmt"
"log"
"net" "net"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/rcode" "github.com/coredns/coredns/plugin/pkg/rcode"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
@ -53,9 +53,9 @@ func notify(zone string, to []string) error {
continue continue
} }
if err := notifyAddr(c, m, t); err != nil { if err := notifyAddr(c, m, t); err != nil {
log.Print("[ERROR] " + err.Error()) log.Error(err.Error())
} else { } else {
log.Printf("[INFO] Sent notify for zone %q to %q", zone, t) log.Infof("Sent notify for zone %q to %q", zone, t)
} }
} }
return nil return nil

View file

@ -1,9 +1,10 @@
package file package file
import ( import (
"log"
"os" "os"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
) )
// TickTime is the default time we use to reload zone. Exported to be tweaked in tests. // TickTime is the default time we use to reload zone. Exported to be tweaked in tests.
@ -25,7 +26,7 @@ func (z *Zone) Reload() error {
case <-tick.C: case <-tick.C:
reader, err := os.Open(z.file) reader, err := os.Open(z.file)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to open zone %q in %q: %v", z.origin, z.file, err) log.Errorf("Failed to open zone %q in %q: %v", z.origin, z.file, err)
continue continue
} }
@ -33,7 +34,7 @@ func (z *Zone) Reload() error {
zone, err := Parse(reader, z.origin, z.file, serial) zone, err := Parse(reader, z.origin, z.file, serial)
if err != nil { if err != nil {
if _, ok := err.(*serialErr); !ok { if _, ok := err.(*serialErr); !ok {
log.Printf("[ERROR] Parsing zone %q: %v", z.origin, err) log.Errorf("Parsing zone %q: %v", z.origin, err)
} }
continue continue
} }
@ -44,7 +45,7 @@ func (z *Zone) Reload() error {
z.Tree = zone.Tree z.Tree = zone.Tree
z.reloadMu.Unlock() z.reloadMu.Unlock()
log.Printf("[INFO] Successfully reloaded zone %q in %q with serial %d", z.origin, z.file, z.Apex.SOA.Serial) log.Infof("Successfully reloaded zone %q in %q with serial %d", z.origin, z.file, z.Apex.SOA.Serial)
z.Notify() z.Notify()
case <-z.reloadShutdown: case <-z.reloadShutdown:

View file

@ -2,7 +2,6 @@ package file
import ( import (
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -15,8 +14,6 @@ import (
) )
func TestZoneReload(t *testing.T) { func TestZoneReload(t *testing.T) {
log.SetOutput(ioutil.Discard)
fileName, rm, err := test.TempFile(".", reloadZoneTest) fileName, rm, err := test.TempFile(".", reloadZoneTest)
if err != nil { if err != nil {
t.Fatalf("failed to create zone: %s", err) t.Fatalf("failed to create zone: %s", err)

View file

@ -1,10 +1,11 @@
package file package file
import ( import (
"log"
"math/rand" "math/rand"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -27,19 +28,19 @@ Transfer:
t := new(dns.Transfer) t := new(dns.Transfer)
c, err := t.In(m, tr) c, err := t.In(m, tr)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to setup transfer `%s' with `%q': %v", z.origin, tr, err) log.Errorf("Failed to setup transfer `%s' with `%q': %v", z.origin, tr, err)
Err = err Err = err
continue Transfer continue Transfer
} }
for env := range c { for env := range c {
if env.Error != nil { if env.Error != nil {
log.Printf("[ERROR] Failed to transfer `%s' from %q: %v", z.origin, tr, env.Error) log.Errorf("Failed to transfer `%s' from %q: %v", z.origin, tr, env.Error)
Err = env.Error Err = env.Error
continue Transfer continue Transfer
} }
for _, rr := range env.RR { for _, rr := range env.RR {
if err := z1.Insert(rr); err != nil { if err := z1.Insert(rr); err != nil {
log.Printf("[ERROR] Failed to parse transfer `%s' from: %q: %v", z.origin, tr, err) log.Errorf("Failed to parse transfer `%s' from: %q: %v", z.origin, tr, err)
Err = err Err = err
continue Transfer continue Transfer
} }
@ -55,7 +56,7 @@ Transfer:
z.Tree = z1.Tree z.Tree = z1.Tree
z.Apex = z1.Apex z.Apex = z1.Apex
*z.Expired = false *z.Expired = false
log.Printf("[INFO] Transferred: %s from %s", z.origin, tr) log.Infof("Transferred: %s from %s", z.origin, tr)
return nil return nil
} }
@ -139,7 +140,7 @@ Restart:
ok, err := z.shouldTransfer() ok, err := z.shouldTransfer()
if err != nil { if err != nil {
log.Printf("[WARNING] Failed retry check %s", err) log.Warningf("Failed retry check %s", err)
continue continue
} }
@ -162,7 +163,7 @@ Restart:
ok, err := z.shouldTransfer() ok, err := z.shouldTransfer()
if err != nil { if err != nil {
log.Printf("[WARNING] Failed refresh check %s", err) log.Warningf("Failed refresh check %s", err)
retryActive = true retryActive = true
continue continue
} }

View file

@ -2,8 +2,6 @@ package file
import ( import (
"fmt" "fmt"
"io/ioutil"
"log"
"testing" "testing"
"github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/test"
@ -72,7 +70,6 @@ const testZone = "secondary.miek.nl."
func TestShouldTransfer(t *testing.T) { func TestShouldTransfer(t *testing.T) {
soa := soa{250} soa := soa{250}
log.SetOutput(ioutil.Discard)
dns.HandleFunc(testZone, soa.Handler) dns.HandleFunc(testZone, soa.Handler)
defer dns.HandleRemove(testZone) defer dns.HandleRemove(testZone)
@ -117,7 +114,6 @@ func TestShouldTransfer(t *testing.T) {
func TestTransferIn(t *testing.T) { func TestTransferIn(t *testing.T) {
soa := soa{250} soa := soa{250}
log.SetOutput(ioutil.Discard)
dns.HandleFunc(testZone, soa.Handler) dns.HandleFunc(testZone, soa.Handler)
defer dns.HandleRemove(testZone) defer dns.HandleRemove(testZone)

View file

@ -2,9 +2,9 @@ package file
import ( import (
"fmt" "fmt"
"log"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -38,7 +38,7 @@ func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (in
j, l := 0, 0 j, l := 0, 0
records = append(records, records[0]) // add closing SOA to the end records = append(records, records[0]) // add closing SOA to the end
log.Printf("[INFO] Outgoing transfer of %d records of zone %s to %s started", len(records), x.origin, state.IP()) log.Infof("Outgoing transfer of %d records of zone %s to %s started", len(records), x.origin, state.IP())
for i, r := range records { for i, r := range records {
l += dns.Len(r) l += dns.Len(r)
if l > transferLength { if l > transferLength {

View file

@ -3,11 +3,12 @@ package health
import ( import (
"io" "io"
"log"
"net" "net"
"net/http" "net/http"
"sync" "sync"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
) )
// Health implements healthchecks by polling plugins. // Health implements healthchecks by polling plugins.
@ -67,7 +68,7 @@ func (h *health) OnShutdown() error {
h.SetOk(false) h.SetOk(false)
if h.lameduck > 0 { if h.lameduck > 0 {
log.Printf("[INFO] Going into lameduck mode for %s", h.lameduck) log.Infof("Going into lameduck mode for %s", h.lameduck)
time.Sleep(h.lameduck) time.Sleep(h.lameduck)
} }

View file

@ -1,7 +1,6 @@
package hosts package hosts
import ( import (
"log"
"os" "os"
"path" "path"
"strings" "strings"
@ -9,6 +8,7 @@ import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/mholt/caddy" "github.com/mholt/caddy"
) )
@ -87,13 +87,13 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
s, err := os.Stat(h.path) s, err := os.Stat(h.path)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Printf("[WARNING] File does not exist: %s", h.path) log.Warningf("File does not exist: %s", h.path)
} else { } else {
return h, c.Errf("unable to access hosts file '%s': %v", h.path, err) return h, c.Errf("unable to access hosts file '%s': %v", h.path, err)
} }
} }
if s != nil && s.IsDir() { if s != nil && s.IsDir() {
log.Printf("[WARNING] hosts file %q is a directory", h.path) log.Warningf("Hosts file %q is a directory", h.path)
} }
} }

View file

@ -3,11 +3,11 @@ package kubernetes
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"net" "net"
"net/http" "net/http"
"github.com/coredns/coredns/plugin/pkg/healthcheck" "github.com/coredns/coredns/plugin/pkg/healthcheck"
"github.com/coredns/coredns/plugin/pkg/log"
) )
type proxyHandler struct { type proxyHandler struct {
@ -27,19 +27,19 @@ func (p *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
d, err := net.Dial(network, address) d, err := net.Dial(network, address)
if err != nil { if err != nil {
log.Printf("[ERROR] Unable to establish connection to upstream %s://%s: %s", network, address, err) log.Errorf("Unable to establish connection to upstream %s://%s: %s", network, address, err)
http.Error(w, fmt.Sprintf("Unable to establish connection to upstream %s://%s: %s", network, address, err), 500) http.Error(w, fmt.Sprintf("Unable to establish connection to upstream %s://%s: %s", network, address, err), 500)
return return
} }
hj, ok := w.(http.Hijacker) hj, ok := w.(http.Hijacker)
if !ok { if !ok {
log.Print("[ERROR] Unable to establish connection: no hijacker") log.Error("Unable to establish connection: no hijacker")
http.Error(w, "Unable to establish connection: no hijacker", 500) http.Error(w, "Unable to establish connection: no hijacker", 500)
return return
} }
nc, _, err := hj.Hijack() nc, _, err := hj.Hijack()
if err != nil { if err != nil {
log.Printf("[ERROR] Unable to hijack connection: %s", err) log.Errorf("Unable to hijack connection: %s", err)
http.Error(w, fmt.Sprintf("Unable to hijack connection: %s", err), 500) http.Error(w, fmt.Sprintf("Unable to hijack connection: %s", err), 500)
return return
} }
@ -48,7 +48,7 @@ func (p *proxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = r.Write(d) err = r.Write(d)
if err != nil { if err != nil {
log.Printf("[ERROR] Unable to copy connection to upstream %s://%s: %s", network, address, err) log.Errorf("Unable to copy connection to upstream %s://%s: %s", network, address, err)
http.Error(w, fmt.Sprintf("Unable to copy connection to upstream %s://%s: %s", network, address, err), 500) http.Error(w, fmt.Sprintf("Unable to copy connection to upstream %s://%s: %s", network, address, err), 500)
return return
} }

View file

@ -1,14 +1,15 @@
package kubernetes package kubernetes
import ( import (
"log"
"math" "math"
"net" "net"
"strings" "strings"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/etcd/msg" "github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
"golang.org/x/net/context" "golang.org/x/net/context"
api "k8s.io/api/core/v1" api "k8s.io/api/core/v1"
@ -50,7 +51,7 @@ func (k *Kubernetes) Transfer(ctx context.Context, state request.Request) (int,
records = append(records, soa...) records = append(records, soa...)
go func(ch chan *dns.Envelope) { go func(ch chan *dns.Envelope) {
j, l := 0, 0 j, l := 0, 0
log.Printf("[INFO] Outgoing transfer of %d records of zone %s to %s started", len(records), state.Zone, state.IP()) log.Infof("Outgoing transfer of %d records of zone %s to %s started", len(records), state.Zone, state.IP())
for i, r := range records { for i, r := range records {
l += dns.Len(r) l += dns.Len(r)
if l > transferLength { if l > transferLength {

View file

@ -2,7 +2,7 @@
package loadbalance package loadbalance
import ( import (
"log" "github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -75,7 +75,7 @@ func roundRobinShuffle(records []dns.RR) {
// Write implements the dns.ResponseWriter interface. // Write implements the dns.ResponseWriter interface.
func (r *RoundRobinResponseWriter) Write(buf []byte) (int, error) { func (r *RoundRobinResponseWriter) Write(buf []byte) (int, error) {
// Should we pack and unpack here to fiddle with the packet... Not likely. // Should we pack and unpack here to fiddle with the packet... Not likely.
log.Print("[WARNING] RoundRobin called with Write: no shuffling records") log.Warning("RoundRobin called with Write: not shuffling records")
n, err := r.ResponseWriter.Write(buf) n, err := r.ResponseWriter.Write(buf)
return n, err return n, err
} }

View file

@ -2,7 +2,6 @@
package metrics package metrics
import ( import (
"log"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -12,6 +11,7 @@ import (
"github.com/coredns/coredns/coremain" "github.com/coredns/coredns/coremain"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics/vars" "github.com/coredns/coredns/plugin/metrics/vars"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -88,7 +88,7 @@ func (m *Metrics) ZoneNames() []string {
func (m *Metrics) OnStartup() error { func (m *Metrics) OnStartup() error {
ln, err := net.Listen("tcp", m.Addr) ln, err := net.Listen("tcp", m.Addr)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to start metrics handler: %s", err) log.Errorf("Failed to start metrics handler: %s", err)
return err return err
} }

View file

@ -3,13 +3,14 @@ package healthcheck
import ( import (
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
) )
// UpstreamHostDownFunc can be used to customize how Down behaves. // UpstreamHostDownFunc can be used to customize how Down behaves.
@ -122,7 +123,7 @@ func (uh *UpstreamHost) HealthCheckURL() {
}() }()
if err != nil { if err != nil {
log.Printf("[WARNING] Host %s health check probe failed: %v", uh.Name, err) log.Warningf("Host %s health check probe failed: %v", uh.Name, err)
atomic.AddInt32(&uh.Fails, 1) atomic.AddInt32(&uh.Fails, 1)
return return
} }
@ -132,7 +133,7 @@ func (uh *UpstreamHost) HealthCheckURL() {
r.Body.Close() r.Body.Close()
if r.StatusCode < 200 || r.StatusCode >= 400 { if r.StatusCode < 200 || r.StatusCode >= 400 {
log.Printf("[WARNING] Host %s health check returned HTTP code %d", uh.Name, r.StatusCode) log.Warningf("Host %s health check returned HTTP code %d", uh.Name, r.StatusCode)
atomic.AddInt32(&uh.Fails, 1) atomic.AddInt32(&uh.Fails, 1)
return return
} }

View file

@ -1,9 +1,10 @@
package healthcheck package healthcheck
import ( import (
"log"
"math/rand" "math/rand"
"sync/atomic" "sync/atomic"
"github.com/coredns/coredns/plugin/pkg/log"
) )
var ( var (
@ -64,7 +65,7 @@ type Spray struct{}
func (r *Spray) Select(pool HostPool) *UpstreamHost { func (r *Spray) Select(pool HostPool) *UpstreamHost {
rnd := rand.Int() % len(pool) rnd := rand.Int() % len(pool)
randHost := pool[rnd] randHost := pool[rnd]
log.Printf("[WARNING] All hosts reported as down, spraying to target: %s", randHost.Name) log.Warningf("All hosts reported as down, spraying to target: %s", randHost.Name)
return randHost return randHost
} }

View file

@ -1,8 +1,6 @@
package healthcheck package healthcheck
import ( import (
"io/ioutil"
"log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
@ -13,8 +11,6 @@ import (
var workableServer *httptest.Server var workableServer *httptest.Server
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
workableServer = httptest.NewServer(http.HandlerFunc( workableServer = httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
// do nothing // do nothing

View file

@ -3,10 +3,11 @@
package pprof package pprof
import ( import (
"log"
"net" "net"
"net/http" "net/http"
pp "net/http/pprof" pp "net/http/pprof"
"github.com/coredns/coredns/plugin/pkg/log"
) )
type handler struct { type handler struct {
@ -18,7 +19,7 @@ type handler struct {
func (h *handler) Startup() error { func (h *handler) Startup() error {
ln, err := net.Listen("tcp", h.addr) ln, err := net.Listen("tcp", h.addr)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to start pprof handler: %s", err) log.Errorf("Failed to start pprof handler: %s", err)
return err return err
} }

View file

@ -5,13 +5,13 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/healthcheck" "github.com/coredns/coredns/plugin/pkg/healthcheck"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -65,7 +65,7 @@ func (g *google) Exchange(ctx context.Context, addr string, state request.Reques
return m, nil return m, nil
} }
log.Printf("[WARNING] Failed to connect to HTTPS backend %q: %s", g.endpoint, backendErr) log.Warningf("Failed to connect to HTTPS backend %q: %s", g.endpoint, backendErr)
return nil, backendErr return nil, backendErr
} }
@ -119,17 +119,17 @@ func (g *google) OnStartup(p *Proxy) error {
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA) new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
if err != nil { if err != nil {
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err) log.Warningf("Failed to bootstrap A records %q: %s", g.endpoint, err)
} else { } else {
addrs, err1 := extractAnswer(new) addrs, err1 := extractAnswer(new)
if err1 != nil { if err1 != nil {
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err1) log.Warningf("Failed to bootstrap A records %q: %s", g.endpoint, err1)
} else { } else {
up := newUpstream(addrs, oldUpstream.(*staticUpstream)) up := newUpstream(addrs, oldUpstream.(*staticUpstream))
p.Upstreams = &[]Upstream{up} p.Upstreams = &[]Upstream{up}
log.Printf("[INFO] Bootstrapping A records %q found: %v", g.endpoint, addrs) log.Infof("Bootstrapping A records %q found: %v", g.endpoint, addrs)
} }
} }
@ -140,24 +140,24 @@ func (g *google) OnStartup(p *Proxy) error {
select { select {
case <-tick.C: case <-tick.C:
log.Printf("[INFO] Resolving A records %q", g.endpoint) log.Infof("Resolving A records %q", g.endpoint)
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA) new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
if err != nil { if err != nil {
log.Printf("[WARNING] Failed to resolve A records %q: %s", g.endpoint, err) log.Warningf("Failed to resolve A records %q: %s", g.endpoint, err)
continue continue
} }
addrs, err1 := extractAnswer(new) addrs, err1 := extractAnswer(new)
if err1 != nil { if err1 != nil {
log.Printf("[WARNING] Failed to resolve A records %q: %s", g.endpoint, err1) log.Warningf("Failed to resolve A records %q: %s", g.endpoint, err1)
continue continue
} }
up := newUpstream(addrs, oldUpstream.(*staticUpstream)) up := newUpstream(addrs, oldUpstream.(*staticUpstream))
p.Upstreams = &[]Upstream{up} p.Upstreams = &[]Upstream{up}
log.Printf("[INFO] Resolving A records %q found: %v", g.endpoint, addrs) log.Infof("Resolving A records %q found: %v", g.endpoint, addrs)
case <-g.quit: case <-g.quit:
return return

View file

@ -3,9 +3,9 @@ package proxy
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"log"
"github.com/coredns/coredns/pb" "github.com/coredns/coredns/pb"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/trace" "github.com/coredns/coredns/plugin/pkg/trace"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
@ -67,7 +67,7 @@ func (g *grpcClient) OnShutdown(p *Proxy) error {
for i, conn := range g.conns { for i, conn := range g.conns {
err := conn.Close() err := conn.Close()
if err != nil { if err != nil {
log.Printf("[WARNING] Error closing connection %d: %s\n", i, err) log.Warningf("Error closing connection %d: %s\n", i, err)
} }
} }
g.conns = []*grpc.ClientConn{} g.conns = []*grpc.ClientConn{}
@ -84,13 +84,13 @@ func (g *grpcClient) OnStartup(p *Proxy) error {
intercept := otgrpc.OpenTracingClientInterceptor(t.Tracer(), otgrpc.IncludingSpans(onlyIfParent)) intercept := otgrpc.OpenTracingClientInterceptor(t.Tracer(), otgrpc.IncludingSpans(onlyIfParent))
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(intercept)) dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(intercept))
} else { } else {
log.Printf("[WARNING] Wrong type for trace plugin reference: %s", p.Trace) log.Warningf("Wrong type for trace plugin reference: %s", p.Trace)
} }
} }
for _, host := range g.upstream.Hosts { for _, host := range g.upstream.Hosts {
conn, err := grpc.Dial(host.Name, dialOpts...) conn, err := grpc.Dial(host.Name, dialOpts...)
if err != nil { if err != nil {
log.Printf("[WARNING] Skipping gRPC host '%s' due to Dial error: %s\n", host.Name, err) log.Warningf("Skipping gRPC host '%s' due to Dial error: %s\n", host.Name, err)
} else { } else {
g.clients[host.Name] = pb.NewDnsServiceClient(conn) g.clients[host.Name] = pb.NewDnsServiceClient(conn)
g.conns = append(g.conns, conn) g.conns = append(g.conns, conn)

View file

@ -2,8 +2,6 @@ package proxy
import ( import (
"fmt" "fmt"
"io/ioutil"
"log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
@ -18,10 +16,6 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
) )
func init() {
log.SetOutput(ioutil.Discard)
}
func TestUnhealthy(t *testing.T) { func TestUnhealthy(t *testing.T) {
// High HC interval, we want to test the HC after failed queries. // High HC interval, we want to test the HC after failed queries.
config := "proxy . %s {\n health_check /healthcheck:%s 10s \nfail_timeout 100ms\n}" config := "proxy . %s {\n health_check /healthcheck:%s 10s \nfail_timeout 100ms\n}"

View file

@ -2,9 +2,10 @@ package reload
import ( import (
"crypto/md5" "crypto/md5"
"log"
"time" "time"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/mholt/caddy" "github.com/mholt/caddy"
) )
@ -36,7 +37,7 @@ func hook(event caddy.EventName, info interface{}) error {
// this should be an instance. ok to panic if not // this should be an instance. ok to panic if not
instance := info.(*caddy.Instance) instance := info.(*caddy.Instance)
md5sum := md5.Sum(instance.Caddyfile().Body()) md5sum := md5.Sum(instance.Caddyfile().Body())
log.Printf("[INFO] Running configuration MD5 = %x\n", md5sum) log.Infof("Running configuration MD5 = %x\n", md5sum)
go func() { go func() {
tick := time.NewTicker(r.interval) tick := time.NewTicker(r.interval)
@ -57,7 +58,7 @@ func hook(event caddy.EventName, info interface{}) error {
r.usage = maybeUsed r.usage = maybeUsed
_, err := instance.Restart(corefile) _, err := instance.Restart(corefile)
if err != nil { if err != nil {
log.Printf("[ERROR] Corefile changed but reload failed: %s\n", err) log.Errorf("Corefile changed but reload failed: %s\n", err)
continue continue
} }
// we are done, if the plugin was not set used, then it is not. // we are done, if the plugin was not set used, then it is not.

View file

@ -1,11 +1,11 @@
package root package root
import ( import (
"log"
"os" "os"
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/mholt/caddy" "github.com/mholt/caddy"
) )
@ -33,7 +33,7 @@ func setup(c *caddy.Controller) error {
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Allow this, because the folder might appear later. // Allow this, because the folder might appear later.
// But make sure the user knows! // But make sure the user knows!
log.Printf("[WARNING] Root path does not exist: %s", config.Root) log.Warningf("Root path does not exist: %s", config.Root)
} else { } else {
return plugin.Error("root", c.Errf("unable to access root path '%s': %v", config.Root, err)) return plugin.Error("root", c.Errf("unable to access root path '%s': %v", config.Root, err))
} }

View file

@ -3,7 +3,6 @@ package root
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -15,8 +14,6 @@ import (
) )
func TestRoot(t *testing.T) { func TestRoot(t *testing.T) {
log.SetOutput(ioutil.Discard)
// Predefined error substrings // Predefined error substrings
parseErrContent := "Error during parsing:" parseErrContent := "Error during parsing:"
unableToAccessErrContent := "unable to access root path" unableToAccessErrContent := "unable to access root path"

View file

@ -1,8 +1,6 @@
package tls package tls
import ( import (
"io/ioutil"
"log"
"strings" "strings"
"testing" "testing"
@ -10,16 +8,14 @@ import (
) )
func TestTLS(t *testing.T) { func TestTLS(t *testing.T) {
log.SetOutput(ioutil.Discard)
tests := []struct { tests := []struct {
input string input string
shouldErr bool shouldErr bool
expectedRoot string // expected root, set to the controller. Empty for negative cases. expectedRoot string // expected root, set to the controller. Empty for negative cases.
expectedErrContent string // substring from the expected error. Empty for positive cases. expectedErrContent string // substring from the expected error. Empty for positive cases.
}{ }{
// positive // positive
// negative // negative
} }
for i, test := range tests { for i, test := range tests {