# HG changeset patch
# User Florent Aide <florent.aide@gmail.com>
# Date 1652369536 -7200
#      Thu May 12 17:32:16 2022 +0200
# Node ID 00dd885393fa2f611dd6fe246be70453a90b508b
# Parent  b5b8ec8eea167724dd02824b571b010972a8f105
runner config now needs a logger

diff --git a/cmd/build.go b/cmd/build.go
--- a/cmd/build.go
+++ b/cmd/build.go
@@ -19,7 +19,7 @@
 // Execute ...
 func (cmd *BuildCmd) Execute([]string) error {
 	Logger.Info().Str("namespace", cmd.Args.Namespace).Msg("starting beaver")
-	config, err := runner.NewConfig(".", cmd.Args.Namespace)
+	config, err := runner.NewConfig(Logger, ".", cmd.Args.Namespace)
 	if err != nil {
 		Logger.Err(err).Msg("failed to prepare config")
 	}
diff --git a/runner/config.go b/runner/config.go
--- a/runner/config.go
+++ b/runner/config.go
@@ -5,6 +5,7 @@
 	"fmt"
 	"text/template"
 
+	"github.com/rs/zerolog"
 	"github.com/spf13/viper"
 	yaml "gopkg.in/yaml.v2"
 )
@@ -39,10 +40,11 @@
 	Kind       string `mapstructure:"kind"`
 	Spec       Spec   `mapstructure:"spec"`
 	Namespace  string
+	Logger     zerolog.Logger
 }
 
 // NewConfig returns a *Config
-func NewConfig(configDir string, namespace string) (*Config, error) {
+func NewConfig(logger zerolog.Logger, configDir string, namespace string) (*Config, error) {
 	// we ONLY search for files named beaver.yml
 	viper.SetConfigName("beaver")
 	viper.AddConfigPath(configDir)
diff --git a/runner/config_test.go b/runner/config_test.go
--- a/runner/config_test.go
+++ b/runner/config_test.go
@@ -5,11 +5,13 @@
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+	"orus.io/cloudcrane/beaver/testutils"
 )
 
 func TestConfig(t *testing.T) {
+	logger := testutils.GetLogger(t)
 	configDir := "fixtures/"
-	config, err := NewConfig(configDir, "ns1")
+	config, err := NewConfig(logger, configDir, "ns1")
 	require.NoError(t, err)
 	// first config.spec.variables entry name should be VAULT_KV in our test file
 	assert.Equal(t, "VAULT_KV", config.Spec.Variables[0].Name)
diff --git a/testutils/logger.go b/testutils/logger.go
new file mode 100644
--- /dev/null
+++ b/testutils/logger.go
@@ -0,0 +1,53 @@
+package testutils
+
+import (
+	"os"
+	"testing"
+
+	"github.com/rs/zerolog"
+)
+
+// NewTestLogger creates a TestLogger
+func NewTestLogger(tb testing.TB) *TestLogger {
+	return &TestLogger{tb}
+}
+
+// TestLogger logs to a t.Log function
+type TestLogger struct {
+	tb testing.TB
+}
+
+// Logger returns a zerolog Logger
+func (tl *TestLogger) Logger() zerolog.Logger {
+	level := zerolog.DebugLevel
+	if os.Getenv("TEST_TRACE") != "" {
+		level = zerolog.TraceLevel
+	}
+	if os.Getenv("TEST_QUIET") != "" {
+		level = zerolog.InfoLevel
+	}
+	return zerolog.New(zerolog.ConsoleWriter{Out: tl}).
+		With().Timestamp().Logger().
+		Level(level)
+}
+
+// Write writes the given string to t.Logf
+func (tl *TestLogger) Write(m []byte) (int, error) {
+	tl.tb.Logf(string(m))
+	return len(m), nil
+}
+
+// SetTB changes the current TB, and returns a function to get back to the
+// previous one
+func (tl *TestLogger) SetTB(tb testing.TB) func() {
+	otb := tl.tb
+	tl.tb = tb
+	return func() {
+		tl.tb = otb
+	}
+}
+
+// GetLogger returns a test Logger
+func GetLogger(tb testing.TB) zerolog.Logger {
+	return NewTestLogger(tb).Logger()
+}