mirror of
https://github.com/coredns/coredns.git
synced 2025-10-30 01:34:21 -04:00
plugin/pkg/log: add plugin logging (#1716)
Add per plugin logging to make it explicit what is logging, if you
include this package under the name clog (coredns log), you can do the
following:
log := clog.NewWithPlugin{whoami{}} // e.g.
And then just log.Info(...); these will then include the plugin ala:
[INFO] plugin/whoami: stuff
So we only need to init the logger and then just use it.
This commit is contained in:
32
plugin/pkg/log/plugin_test.go
Normal file
32
plugin/pkg/log/plugin_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
golog "log"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type p struct{}
|
||||
|
||||
func (p p) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p p) Name() string { return "testplugin" }
|
||||
|
||||
func TestPlugins(t *testing.T) {
|
||||
var f bytes.Buffer
|
||||
const ts = "test"
|
||||
golog.SetOutput(&f)
|
||||
|
||||
lg := NewWithPlugin(p{})
|
||||
|
||||
lg.Info(ts)
|
||||
if x := f.String(); !strings.Contains(x, "plugin/testplugin") {
|
||||
t.Errorf("Expected log to be %s, got %s", info+ts, x)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user