mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	* pkg/log: ability for debug logs When the debug plugin is enabled all log.Debug calls will print to standard; if not there are a noop (almost). The log package wraps some standard log functions as well, so just replacing "log" with "plugin/pkg/log" should be enough to use this package. * docs * Add docs * lint * Test fallthrough to log pkg as well * simple package - up test coverage * add other log levels as well * update docs
		
			
				
	
	
		
			62 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.2 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)
 | |
| 	}
 | |
| 
 | |
| 	D = true
 | |
| 	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 TestDebugx(t *testing.T) {
 | |
| 	var f bytes.Buffer
 | |
| 	golog.SetOutput(&f)
 | |
| 
 | |
| 	D = true
 | |
| 
 | |
| 	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)
 | |
| 	}
 | |
| 
 | |
| 	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)
 | |
| 	}
 | |
| 	Warning(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, warning+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", warning+ts, x)
 | |
| 	}
 | |
| 	Error(ts)
 | |
| 	if x := f.String(); !strings.Contains(x, err+ts) {
 | |
| 		t.Errorf("Expected log to be %s, got %s", err+ts, x)
 | |
| 	}
 | |
| }
 |