configurable log level for tests via VAULT_TEST_LOG_LEVEL

This commit is contained in:
Raymond Ho
2023-12-19 14:40:38 -08:00
parent f6225b74ee
commit 612b6fc62a
2 changed files with 9 additions and 2 deletions

View File

@@ -382,6 +382,7 @@ jobs:
VAULT_TEST_LOG_DIR="$(pwd)/test-results/go-test/logs-${{ matrix.id }}"
export VAULT_TEST_LOG_DIR
mkdir -p "$VAULT_TEST_LOG_DIR"
export VAULT_TEST_LOG_LEVEL=info
# shellcheck disable=SC2086 # can't quote RERUN_FAILS

View File

@@ -19,6 +19,8 @@ import (
"github.com/hashicorp/eventlogger"
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/go-testing-interface"
"github.com/hashicorp/vault/audit"
"github.com/hashicorp/vault/builtin/credential/approle"
"github.com/hashicorp/vault/internal/observability/event"
@@ -27,7 +29,6 @@ import (
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/helper/salt"
"github.com/hashicorp/vault/sdk/logical"
"github.com/mitchellh/go-testing-interface"
)
var (
@@ -561,6 +562,11 @@ func NewTestLogger(t testing.T) *TestLogger {
var logPath string
output := os.Stderr
logLevel := hclog.Trace
logLevelRaw := os.Getenv("VAULT_TEST_LOG_LEVEL")
if logLevelRaw != "" {
logLevel = hclog.LevelFromString(logLevelRaw)
}
logDir := os.Getenv("VAULT_TEST_LOG_DIR")
if logDir != "" {
logPath = filepath.Join(logDir, t.Name()+".log")
@@ -586,7 +592,7 @@ func NewTestLogger(t testing.T) *TestLogger {
})
sink := hclog.NewSinkAdapter(&hclog.LoggerOptions{
Output: output,
Level: hclog.Trace,
Level: logLevel,
IndependentLevels: true,
})
logger.RegisterSink(sink)