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
36 changed files with 101 additions and 132 deletions

View File

@@ -4,9 +4,9 @@ package file
import (
"fmt"
"io"
"log"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"
"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)
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()
if ok {
z.TransferIn()
} 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 {
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
}
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
}
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
}

View File

@@ -2,9 +2,9 @@ package file
import (
"fmt"
"log"
"net"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/rcode"
"github.com/coredns/coredns/request"
@@ -53,9 +53,9 @@ func notify(zone string, to []string) error {
continue
}
if err := notifyAddr(c, m, t); err != nil {
log.Print("[ERROR] " + err.Error())
log.Error(err.Error())
} 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

View File

@@ -1,9 +1,10 @@
package file
import (
"log"
"os"
"time"
"github.com/coredns/coredns/plugin/pkg/log"
)
// 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:
reader, err := os.Open(z.file)
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
}
@@ -33,7 +34,7 @@ func (z *Zone) Reload() error {
zone, err := Parse(reader, z.origin, z.file, serial)
if err != nil {
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
}
@@ -44,7 +45,7 @@ func (z *Zone) Reload() error {
z.Tree = zone.Tree
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()
case <-z.reloadShutdown:

View File

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

View File

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

View File

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

View File

@@ -2,9 +2,9 @@ package file
import (
"fmt"
"log"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"
"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
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 {
l += dns.Len(r)
if l > transferLength {