mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	pkg/log: ability for debug logs (#1689)
* 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
This commit is contained in:
		
							
								
								
									
										61
									
								
								plugin/pkg/log/log_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								plugin/pkg/log/log_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| 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) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user