mirror of https://github.com/hashicorp/consul
sdk: add TestLogLevel for setting log level in tests
And default log level to WARN.pull/12265/head
parent
f020cedab2
commit
b058845110
|
@ -67,7 +67,7 @@ func NewTestACLAgent(t *testing.T, name string, hcl string, resolveAuthz authzRe
|
||||||
|
|
||||||
bd.Logger = hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
bd.Logger = hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Name: name,
|
Name: name,
|
||||||
Level: hclog.Debug,
|
Level: testutil.TestLogLevel,
|
||||||
Output: logBuffer,
|
Output: logBuffer,
|
||||||
TimeFormat: "04:05.000",
|
TimeFormat: "04:05.000",
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,10 +8,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/lib"
|
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
|
||||||
"github.com/hashicorp/go-hclog"
|
"github.com/hashicorp/go-hclog"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/lib"
|
||||||
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAE_scaleFactor(t *testing.T) {
|
func TestAE_scaleFactor(t *testing.T) {
|
||||||
|
@ -401,7 +402,6 @@ func (m *mock) SyncChanges() error {
|
||||||
|
|
||||||
func testSyncer(t *testing.T) *StateSyncer {
|
func testSyncer(t *testing.T) *StateSyncer {
|
||||||
logger := hclog.New(&hclog.LoggerOptions{
|
logger := hclog.New(&hclog.LoggerOptions{
|
||||||
Level: 0,
|
|
||||||
Output: testutil.NewLogBuffer(t),
|
Output: testutil.NewLogBuffer(t),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -507,7 +507,7 @@ func newDefaultDeps(t *testing.T, c *Config) Deps {
|
||||||
|
|
||||||
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Name: c.NodeName,
|
Name: c.NodeName,
|
||||||
Level: hclog.Debug,
|
Level: testutil.TestLogLevel,
|
||||||
Output: testutil.NewLogBuffer(t),
|
Output: testutil.NewLogBuffer(t),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1445,7 +1445,7 @@ func TestLeader_ConfigEntryBootstrap_Fail(t *testing.T) {
|
||||||
|
|
||||||
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Name: config.NodeName,
|
Name: config.NodeName,
|
||||||
Level: hclog.Debug,
|
Level: testutil.TestLogLevel,
|
||||||
Output: io.MultiWriter(pw, testutil.NewLogBuffer(t)),
|
Output: io.MultiWriter(pw, testutil.NewLogBuffer(t)),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
tokenStore "github.com/hashicorp/consul/agent/token"
|
tokenStore "github.com/hashicorp/consul/agent/token"
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/hashicorp/consul/testrpc"
|
||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
|
@ -2760,7 +2761,7 @@ func (m *mockQueryServer) GetLogger() hclog.Logger {
|
||||||
m.Logger = hclog.New(&hclog.LoggerOptions{
|
m.Logger = hclog.New(&hclog.LoggerOptions{
|
||||||
Name: "mock_query",
|
Name: "mock_query",
|
||||||
Output: m.LogBuffer,
|
Output: m.LogBuffer,
|
||||||
Level: hclog.Debug,
|
Level: testutil.TestLogLevel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return m.Logger
|
return m.Logger
|
||||||
|
|
|
@ -25,10 +25,7 @@ func init() {
|
||||||
|
|
||||||
func GetBufferedLogger() hclog.Logger {
|
func GetBufferedLogger() hclog.Logger {
|
||||||
localLogBuffer = new(bytes.Buffer)
|
localLogBuffer = new(bytes.Buffer)
|
||||||
return hclog.New(&hclog.LoggerOptions{
|
return hclog.New(&hclog.LoggerOptions{Output: localLogBuffer})
|
||||||
Level: 0,
|
|
||||||
Output: localLogBuffer,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type fauxConnPool struct {
|
type fauxConnPool struct {
|
||||||
|
|
|
@ -159,7 +159,7 @@ func (a *TestAgent) Start(t *testing.T) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||||
Level: hclog.Debug,
|
Level: testutil.TestLogLevel,
|
||||||
Output: logOutput,
|
Output: logOutput,
|
||||||
TimeFormat: "04:05.000",
|
TimeFormat: "04:05.000",
|
||||||
Name: name,
|
Name: name,
|
||||||
|
|
|
@ -10,6 +10,20 @@ import (
|
||||||
"github.com/hashicorp/go-hclog"
|
"github.com/hashicorp/go-hclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestLogLevel is set from the TEST_LOG_LEVEL environment variable. It can
|
||||||
|
// be used by tests to set the log level of a hclog.Logger. Defaults to
|
||||||
|
// hclog.Warn if the environment variable is unset, or if the value of the
|
||||||
|
// environment variable can not be matched to a log level.
|
||||||
|
var TestLogLevel = testLogLevel()
|
||||||
|
|
||||||
|
func testLogLevel() hclog.Level {
|
||||||
|
level := hclog.LevelFromString(os.Getenv("TEST_LOG_LEVEL"))
|
||||||
|
if level != hclog.NoLevel {
|
||||||
|
return level
|
||||||
|
}
|
||||||
|
return hclog.Warn
|
||||||
|
}
|
||||||
|
|
||||||
func Logger(t TestingTB) hclog.InterceptLogger {
|
func Logger(t TestingTB) hclog.InterceptLogger {
|
||||||
return LoggerWithOutput(t, NewLogBuffer(t))
|
return LoggerWithOutput(t, NewLogBuffer(t))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue