Skip to content

Commit

Permalink
Add NewTestLoggerWithSuffix for tests that need multiple log files. (#…
Browse files Browse the repository at this point in the history
…26879) (#26897)

Co-authored-by: Victor Rodriguez <[email protected]>
  • Loading branch information
1 parent 3fb313a commit 6c77a30
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion helper/testhelpers/corehelpers/corehelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,20 @@ type TestLogger struct {
}

func NewTestLogger(t testing.T) *TestLogger {
return NewTestLoggerWithSuffix(t, "")
}

func NewTestLoggerWithSuffix(t testing.T, logFileSuffix string) *TestLogger {
var logFile *os.File
var logPath string
output := os.Stderr

logDir := os.Getenv("VAULT_TEST_LOG_DIR")
if logDir != "" {
logPath = filepath.Join(logDir, t.Name()+".log")
if logFileSuffix != "" && !strings.HasPrefix(logFileSuffix, "_") {
logFileSuffix = "_" + logFileSuffix
}
logPath = filepath.Join(logDir, t.Name()+logFileSuffix+".log")
// t.Name may include slashes.
dir, _ := filepath.Split(logPath)
err := os.MkdirAll(dir, 0o755)
Expand Down

0 comments on commit 6c77a30

Please sign in to comment.