diff --git a/pkg/context/context.go b/pkg/context/context.go index 61a9a2e62998..890ad1b3457c 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -3,18 +3,26 @@ package context import ( "context" "fmt" + "os" "runtime/debug" "sync" "time" "github.com/go-logr/logr" + "github.com/trufflesecurity/trufflehog/v3/pkg/log" ) var ( // defaultLogger can be set via SetDefaultLogger. - defaultLogger logr.Logger = logr.Discard() + // It is initialized to write to stderr. To disable, you can call + // SetDefaultLogger with logr.Discard(). + defaultLogger logr.Logger ) +func init() { + defaultLogger, _ = log.New("context", log.WithConsoleSink(os.Stderr)) +} + // Context wraps context.Context and includes an additional Logger() method. type Context interface { context.Context @@ -136,7 +144,9 @@ func AddLogger(parent context.Context) Context { } // SetupDefaultLogger sets the package-level global default logger that will be -// used for Background and TODO contexts. +// used for Background and TODO contexts. On startup, the default logger will +// be configured to output logs to stderr. Use logr.Discard() to disable all +// logs from Contexts. func SetDefaultLogger(l logr.Logger) { defaultLogger = l } diff --git a/pkg/context/context_test.go b/pkg/context/context_test.go index 6ef93227adde..5438540abd22 100644 --- a/pkg/context/context_test.go +++ b/pkg/context/context_test.go @@ -158,7 +158,7 @@ func TestWithValues(t *testing.T) { assert.NotContains(t, logs[6], `what does this do?`) } -func TestDiscardLogger(t *testing.T) { +func TestDefaultLogger(t *testing.T) { var panicked bool defer func() { if r := recover(); r != nil {