Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewTestLoggerWithSuffix for tests that need multiple log files #26879

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion helper/testhelpers/corehelpers/corehelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
"time"

"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -210,13 +211,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
Loading