Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load config before initializing logger #66

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading