mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	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>
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package log
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	golog "log"
 | |
| 	"strings"
 | |
| 	"testing"
 | |
| )
 | |
| 
 | |
| func TestDebug(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	// D == false
 | |
| 	Debug("debug")
 | |
| 	if x := f.String(); x != "" {
 | |
| 		t.Errorf("Expected no debug logs, got %s", x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 
 | |
| 	D.Set()
 | |
| 	Debug("debug")
 | |
| 	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) {
 | |
| 	var f bytes.Buffer
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	D.Set()
 | |
| 
 | |
| 	Debugf("%s", "debug")
 | |
| 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | |
| 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 
 | |
| 	Debug("debug")
 | |
| 	if x := f.String(); !strings.Contains(x, debug+"debug") {
 | |
| 		t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestLevels(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	const ts = "test"
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	Info(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, info+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", info+ts, x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 	Warning(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, warning+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", warning+ts, x)
 | |
| 	}
 | |
| 	f.Reset()
 | |
| 	Error(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, err+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", err+ts, x)
 | |
| 	}
 | |
| }
 |