mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 00:04:15 -04:00
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>
This commit is contained in:
@@ -64,6 +64,10 @@ 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
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Package log implements a small wrapper around the std lib log package.
|
// Package log implements a small wrapper around the std lib log package. It
|
||||||
// It implements log levels by prefixing the logs with the current time
|
// implements log levels by prefixing the logs with [INFO], [DEBUG], [WARNING]
|
||||||
// with in RFC3339Milli and [INFO], [DEBUG], [WARNING] or [ERROR].
|
// or [ERROR]. Debug logging is available and enabled if the *debug* plugin is
|
||||||
// Debug logging is available and enabled if the *debug* plugin is used.
|
// used.
|
||||||
//
|
//
|
||||||
// log.Info("this is some logging"), will log on the Info level.
|
// log.Info("this is some logging"), will log on the Info level.
|
||||||
//
|
//
|
||||||
@@ -25,14 +25,21 @@ type d struct {
|
|||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets d to true.
|
// Set enables debug logging.
|
||||||
func (d *d) Set() {
|
func (d *d) Set() {
|
||||||
d.Lock()
|
d.Lock()
|
||||||
d.on = true
|
d.on = true
|
||||||
d.Unlock()
|
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 {
|
func (d *d) Value() bool {
|
||||||
d.RLock()
|
d.RLock()
|
||||||
b := d.on
|
b := d.on
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ func TestDebug(t *testing.T) {
|
|||||||
if x := f.String(); !strings.Contains(x, debug+"debug") {
|
if x := f.String(); !strings.Contains(x, debug+"debug") {
|
||||||
t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
|
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) {
|
func TestDebugx(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user