You need to sign in or sign up before continuing.
Commit f36715e8 authored by Olivier Lemasle's avatar Olivier Lemasle Committed by GitHub

Enable debug globally if enabled in any server config (#4007)

* Enable debug globally if enabled in any server config

It was currently enabled only if the plugin debug
was enabled in the last server config of the Corefile.
Signed-off-by: default avatarOlivier Lemasle <o.lemasle@gmail.com>

* Add test and update debug's README
Signed-off-by: default avatarOlivier Lemasle <o.lemasle@gmail.com>
parent f6262eb2
...@@ -66,10 +66,6 @@ func NewServer(addr string, group []*Config) (*Server, error) { ...@@ -66,10 +66,6 @@ func NewServer(addr string, group []*Config) (*Server, error) {
if site.Debug { if site.Debug {
s.debug = true s.debug = true
log.D.Set() log.D.Set()
} else {
// When reloading we need to explicitly disable debug logging if it is now disabled.
s.debug = false
log.D.Clear()
} }
// set the config per zone // set the config per zone
s.zones[site.Zone] = site s.zones[site.Zone] = site
...@@ -97,6 +93,11 @@ func NewServer(addr string, group []*Config) (*Server, error) { ...@@ -97,6 +93,11 @@ func NewServer(addr string, group []*Config) (*Server, error) {
site.pluginChain = stack site.pluginChain = stack
} }
if !s.debug {
// When reloading we need to explicitly disable debug logging if it is now disabled.
log.D.Clear()
}
return s, nil return s, nil
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns" "github.com/miekg/dns"
...@@ -48,6 +49,33 @@ func TestNewServer(t *testing.T) { ...@@ -48,6 +49,33 @@ func TestNewServer(t *testing.T) {
} }
} }
func TestDebug(t *testing.T) {
configNoDebug, configDebug := testConfig("dns", testPlugin{}), testConfig("dns", testPlugin{})
configDebug.Debug = true
s1, err := NewServer("127.0.0.1:53", []*Config{configDebug, configNoDebug})
if err != nil {
t.Errorf("Expected no error for NewServer, got %s", err)
}
if !s1.debug {
t.Errorf("Expected debug mode enabled for server s1")
}
if !log.D.Value() {
t.Errorf("Expected debug logging enabled")
}
s2, err := NewServer("127.0.0.1:53", []*Config{configNoDebug})
if err != nil {
t.Errorf("Expected no error for NewServer, got %s", err)
}
if s2.debug {
t.Errorf("Expected debug mode disabled for server s2")
}
if log.D.Value() {
t.Errorf("Expected debug logging disabled")
}
}
func BenchmarkCoreServeDNS(b *testing.B) { func BenchmarkCoreServeDNS(b *testing.B) {
s, err := NewServer("127.0.0.1:53", []*Config{testConfig("dns", testPlugin{})}) s, err := NewServer("127.0.0.1:53", []*Config{testConfig("dns", testPlugin{})})
if err != nil { if err != nil {
......
...@@ -12,6 +12,9 @@ will be printed to standard output. ...@@ -12,6 +12,9 @@ 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.
Enabling this plugin is process-wide: enabling *debug* in at least one server block enables
debug mode globally.
## Syntax ## Syntax
~~~ txt ~~~ txt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment