Skip to content

Commit

Permalink
fix: load config before initializing logger (#66)
Browse files Browse the repository at this point in the history
* fix: load config before initializing logger

* chore: use a switch statement for Config.Value()

Co-authored-by: Alyx Holms <[email protected]>

---------

Co-authored-by: Alyx Holms <[email protected]>
  • Loading branch information
computator and superlinkx authored Dec 8, 2023
1 parent faeb09f commit 6fad14d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type azurehoundSvc struct {
}

func (s *azurehoundSvc) Init(env svc.Environment) error {
config.LoadValues(nil, config.Options())
config.SetAzureDefaults()

if logr, err := logger.GetLogger(); err != nil {
return err
} else {
log = *logr

config.LoadValues(nil, config.Options())
config.SetAzureDefaults()

if config.ConfigFileUsed() != "" {
log.V(1).Info(fmt.Sprintf("Config File: %v", config.ConfigFileUsed()))
}
Expand Down
7 changes: 5 additions & 2 deletions config/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ type Config struct {
}

func (s Config) Value() interface{} {
if reflect.ValueOf(s.Default).Kind() == reflect.Slice {
switch reflect.ValueOf(s.Default).Kind() {
case reflect.Slice:
return viper.GetStringSlice(s.Name)
} else {
case reflect.Int:
return viper.GetInt(s.Name)
default:
return viper.Get(s.Name)
}
}
Expand Down
5 changes: 0 additions & 5 deletions logger/log_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ func setupLogger() (*logr.Logger, error) {
options.Writers = append(options.Writers, eventLogWriter)
}

// XXX: This is gross, however, reading in the config file when starting the process as a windows service before
// initializing the eventLogWriter causes the program to panic. It doesn't make sense as to why it does that but
// this call will have to remain here until we can figure out what's going on.
config.LoadValues(nil, config.Options())

// emit logs to file if configured
if fileLogWriter := getFileLogLevelWriter(); fileLogWriter != nil {
options.Writers = append(options.Writers, fileLogWriter)
Expand Down

0 comments on commit 6fad14d

Please sign in to comment.