Skip to content

Commit

Permalink
add logger to config
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
Pavel Okhlopkov committed Oct 24, 2024
1 parent b19ae1f commit 3800619
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ type Config struct {
logEntry *unilogger.Logger
}

func NewConfig() *Config {
func NewConfig(logger *unilogger.Logger) *Config {
return &Config{
params: make(map[string]*Parameter),
values: make(map[string]string),
temporalValues: make(map[string]*TemporalValue),
errors: make(map[string]error),
logEntry: unilogger.NewLogger(unilogger.Options{}).With(slog.String("component", "runtimeConfig")),
logEntry: logger.With(slog.String("component", "runtimeConfig")),
}
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"
"time"

"github.com/flant/shell-operator/pkg/unilogger"
"github.com/stretchr/testify/assert"
)

func TestConfig_Register(t *testing.T) {
c := NewConfig()
c := NewConfig(unilogger.NewNop())

c.Register("log.level", "", "info", nil, nil)

Expand All @@ -32,7 +33,7 @@ func TestConfig_Register(t *testing.T) {
}

func TestConfig_OnChange(t *testing.T) {
c := NewConfig()
c := NewConfig(unilogger.NewNop())

newValue := ""
c.Register("log.level", "", "info", func(oldValue string, n string) error {
Expand Down Expand Up @@ -66,7 +67,7 @@ func TestConfig_OnChange(t *testing.T) {

func TestConfig_Errors(t *testing.T) {
var err error
c := NewConfig()
c := NewConfig(unilogger.NewNop())

c.Register("log.level", "", "info", func(oldValue string, n string) error {
if n == "debug" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/shell-operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Init initialize logging, ensures directories and creates
// a ShellOperator instance with all dependencies.
func Init(logger *unilogger.Logger) (*ShellOperator, error) {
runtimeConfig := config.NewConfig()
runtimeConfig := config.NewConfig(logger)
// Init logging subsystem.
app.SetupLogging(runtimeConfig, logger)

Expand Down

0 comments on commit 3800619

Please sign in to comment.