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 1 commit
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
4 changes: 3 additions & 1 deletion config/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ type Config struct {
}

func (s Config) Value() interface{} {
if reflect.ValueOf(s.Default).Kind() == reflect.Slice {
if defkind := reflect.ValueOf(s.Default).Kind(); defkind == reflect.Slice {
return viper.GetStringSlice(s.Name)
} else if defkind == reflect.Int {
return viper.GetInt(s.Name)
} else {
return viper.Get(s.Name)
}
computator marked this conversation as resolved.
Show resolved Hide resolved
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