diff options
author | 2019-10-17 15:53:11 +0100 | |
---|---|---|
committer | 2019-10-17 15:53:11 +0100 | |
commit | 5f114d38cab74f0c5c99b03ffe99f5607e393a92 (patch) | |
tree | 0aea9f0e38bb77fd3e8f0b4fde41e2905d65d262 /plugin | |
parent | c187d8fa01f94c7b5c94dff0386bada2fe6a92aa (diff) | |
download | coredns-5f114d38cab74f0c5c99b03ffe99f5607e393a92.tar.gz coredns-5f114d38cab74f0c5c99b03ffe99f5607e393a92.tar.zst coredns-5f114d38cab74f0c5c99b03ffe99f5607e393a92.zip |
pkg/log: add Clear to stop debug logging (#3372)
When reloading we need to disable debug output when the debug plugin is
removed from the config file. Add a `Clear` function to pkg/log and use
it in the server server.
Add test case in pkg/log, for actuall check I manually checked the
output by sprinkling some debug statements in the startup and checking
with sending SIGUSR1.
Also clear up the comments in pkg/log to remove the text about time
stamping.
Fixes: #3035
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/pkg/log/log.go | 19 | ||||
-rw-r--r-- | plugin/pkg/log/log_test.go | 7 |
2 files changed, 20 insertions, 6 deletions
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) { |