github.com/rohankumardubey/nomad@v0.11.8/command/agent/http_stdlog_test.go (about) 1 package agent 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/hashicorp/go-hclog" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestHttpServerLoggerFilters_Level_Info(t *testing.T) { 12 var buf bytes.Buffer 13 hclogger := hclog.New(&hclog.LoggerOptions{ 14 Name: "testlog", 15 Output: &buf, 16 Level: hclog.Info, 17 }) 18 19 stdlogger := newHTTPServerLogger(hclogger) 20 21 // spurious logging would be filtered out 22 stdlogger.Printf("spurious logging: %v", "arg") 23 require.Empty(t, buf.String()) 24 25 // panics are included 26 stdlogger.Printf("panic while processing: %v", "endpoint") 27 require.Contains(t, buf.String(), "[ERROR] testlog: panic while processing: endpoint") 28 29 } 30 31 func TestHttpServerLoggerFilters_Level_Trace(t *testing.T) { 32 var buf bytes.Buffer 33 hclogger := hclog.New(&hclog.LoggerOptions{ 34 Name: "testlog", 35 Output: &buf, 36 Level: hclog.Trace, 37 }) 38 39 stdlogger := newHTTPServerLogger(hclogger) 40 41 // spurious logging will be included as Trace level 42 stdlogger.Printf("spurious logging: %v", "arg") 43 require.Contains(t, buf.String(), "[TRACE] testlog: spurious logging: arg") 44 45 stdlogger.Printf("panic while processing: %v", "endpoint") 46 require.Contains(t, buf.String(), "[ERROR] testlog: panic while processing: endpoint") 47 48 }