Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,16 @@ func isHealthExtensionSet() bool {
}

func resolveCollectorLog() *Log {
return &Log{
log := &Log{
Level: viperInstance.GetString(CollectorLogLevelKey),
Path: viperInstance.GetString(CollectorLogPathKey),
}

if !viperInstance.IsSet(CollectorLogLevelKey) {
log.Level = viperInstance.GetString(LogLevelKey)
}

return log
}

func resolveCommand() *Command {
Expand Down
26 changes: 26 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,32 @@ func TestResolveCollector(t *testing.T) {
})
}

func TestResolveCollectorLog(t *testing.T) {
t.Run("Test 1: OTel Log Level Set In Config", func(t *testing.T) {
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))

viperInstance.Set(CollectorLogLevelKey, "info")
viperInstance.Set(CollectorLogPathKey, "/tmp/collector.log")
viperInstance.Set(LogLevelKey, "debug")

log := resolveCollectorLog()

// Check
assert.Equal(t, "info", log.Level)
assert.Equal(t, "/tmp/collector.log", log.Path)
})

t.Run("Test 2: OTel Log Level Not Set In Config", func(t *testing.T) {
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
viperInstance.Set(LogLevelKey, "debug")
viperInstance.Set(CollectorLogPathKey, "/tmp/collector.log")

log := resolveCollectorLog()
assert.Equal(t, "debug", log.Level)
assert.Equal(t, "/tmp/collector.log", log.Path)
})
}

func TestCommand(t *testing.T) {
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
expected := agentConfig().Command
Expand Down