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 stdout
This commit is contained in:
R.B. Boyer 2019-02-21 10:35:45 -06:00 committed by GitHub
commit 2e35985480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -1,12 +1,20 @@
package testutil
import (
"fmt"
"io"
"log"
"os"
"strings"
"testing"
)
var sendTestLogsToStdout bool
func init() {
sendTestLogsToStdout = os.Getenv("NOLOGBUFFER") == "1"
}
func TestLogger(t testing.TB) *log.Logger {
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) {
tw.t.Helper()
if sendTestLogsToStdout {
fmt.Fprint(os.Stdout, strings.TrimSpace(string(p))+"\n")
} else {
tw.t.Log(strings.TrimSpace(string(p)))
}
return len(p), nil
}