diff options
-rw-r--r-- | core/dnsserver/server.go | 4 | ||||
-rw-r--r-- | plugin/pkg/log/log.go | 19 | ||||
-rw-r--r-- | plugin/pkg/log/log_test.go | 7 |
3 files changed, 24 insertions, 6 deletions
diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go index 587f219dd..9a6fea1ce 100644 --- a/core/dnsserver/server.go +++ b/core/dnsserver/server.go @@ -64,6 +64,10 @@ func NewServer(addr string, group []*Config) (*Server, error) { if site.Debug { s.debug = true 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 s.zones[site.Zone] = site diff --git a/plugin/pkg/log/log.go b/plugin/pkg/log/log.go index 2d8ba78d8..6f9dd07c6 100644 --- a/plugin/pkg/log/log.go +++ b/plugin/pkg/log/log.go @@ -1,7 +1,7 @@ -// Package log implements a small wrapper around the std lib log package. -// It implements log levels by prefixing the logs with the current time -// with in RFC3339Milli and [INFO], [DEBUG], [WARNING] or [ERROR]. -// Debug logging is available and enabled if the *debug* plugin is used. +// Package log implements a small wrapper around the std lib log package. It +// implements log levels by prefixing the logs with [INFO], [DEBUG], [WARNING] +// or [ERROR]. Debug logging is available and enabled if the *debug* plugin is +// used. // // log.Info("this is some logging"), will log on the Info level. // @@ -25,14 +25,21 @@ type d struct { sync.RWMutex } -// Set sets d to true. +// Set enables debug logging. func (d *d) Set() { d.Lock() d.on = true d.Unlock() } -// Value return the boolean value of d. +// Clear disables debug logging. +func (d *d) Clear() { + d.Lock() + d.on = false + d.Unlock() +} + +// Value returns if debug logging is enabled. func (d *d) Value() bool { d.RLock() b := d.on diff --git a/plugin/pkg/log/log_test.go b/plugin/pkg/log/log_test.go index 4f0dc4f43..32c1d39ad 100644 --- a/plugin/pkg/log/log_test.go +++ b/plugin/pkg/log/log_test.go @@ -23,6 +23,13 @@ func TestDebug(t *testing.T) { if x := f.String(); !strings.Contains(x, debug+"debug") { t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x) } + f.Reset() + + D.Clear() + Debug("debug") + if x := f.String(); x != "" { + t.Errorf("Expected no debug logs, got %s", x) + } } func TestDebugx(t *testing.T) { |