Skip to content

Commit

Permalink
Merge pull request #73 from telekom-mms/feature/log-config-on-daemon-…
Browse files Browse the repository at this point in the history
…startup

Log Daemon config on startup in verbose mode
  • Loading branch information
hwipl authored Apr 17, 2024
2 parents 17bef04 + ac974ea commit f83341a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/daemon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func run(args []string) error {
log.SetLevel(log.DebugLevel)
}

// log config
log.WithField("config", config).Debug("Daemon starting with valid config")

// prepare directories
if err := prepareFolders(config); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions internal/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ type Config struct {
TND *tnd.Config
}

// String returns the configuration as string.
func (c *Config) String() string {
b, _ := json.Marshal(c)
return string(b)
}

// Valid returns whether config is valid.
func (c *Config) Valid() bool {
if c == nil ||
Expand Down
15 changes: 15 additions & 0 deletions internal/daemon/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ import (
"github.com/telekom-mms/tnd/pkg/tnd"
)

// TestConfigString tests String of Config.
func TestConfigString(t *testing.T) {
// test new config
c := NewConfig()
if c.String() == "" {
t.Errorf("string should not be empty: %s", c.String())
}

// test nil
c = nil
if c.String() != "null" {
t.Errorf("string should be null: %s", c.String())
}
}

// TestConfigValid tests Valid of Config.
func TestConfigValid(t *testing.T) {
// test invalid
Expand Down

0 comments on commit f83341a

Please sign in to comment.