mirror of https://github.com/hashicorp/consul
Merge pull request #5344 from hashicorp/test-no-log-buffer
testutil: Set the environment variable NOLOGBUFFER=1 to have test agent logs go straight to stdoutpull/5370/head
commit
1598c787ae
|
@ -1,12 +1,20 @@
|
||||||
package testutil
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var sendTestLogsToStdout bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
sendTestLogsToStdout = os.Getenv("NOLOGBUFFER") == "1"
|
||||||
|
}
|
||||||
|
|
||||||
func TestLogger(t testing.TB) *log.Logger {
|
func TestLogger(t testing.TB) *log.Logger {
|
||||||
return log.New(&testWriter{t}, "test: ", log.LstdFlags)
|
return log.New(&testWriter{t}, "test: ", log.LstdFlags)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +33,10 @@ type testWriter struct {
|
||||||
|
|
||||||
func (tw *testWriter) Write(p []byte) (n int, err error) {
|
func (tw *testWriter) Write(p []byte) (n int, err error) {
|
||||||
tw.t.Helper()
|
tw.t.Helper()
|
||||||
tw.t.Log(strings.TrimSpace(string(p)))
|
if sendTestLogsToStdout {
|
||||||
|
fmt.Fprint(os.Stdout, strings.TrimSpace(string(p))+"\n")
|
||||||
|
} else {
|
||||||
|
tw.t.Log(strings.TrimSpace(string(p)))
|
||||||
|
}
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue