Skip to content

Commit

Permalink
feat: Improve logging for running hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Jan 29, 2023
1 parent fe19b28 commit cae14d5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/game_launcher/game_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
HookWhenAlways HookWhen = "always"
HookWhenPreLaunch HookWhen = "pre-launch"
HookWhenPostLaunch HookWhen = "post-launch"

handlerLogKey = "handler"
)

type FileRepository interface {
Expand Down Expand Up @@ -95,19 +97,21 @@ func (l *GameLauncher) StartGame(u *url.URL, config Config, launchType LaunchTyp
func (l *GameLauncher) runHooks(u *url.URL, config Config, launchType LaunchType, handlers map[string]HookHandler, when HookWhen) error {
for _, hc := range config.HookConfigs {
if hc.When != when && hc.When != HookWhenAlways {
log.Debug().Str("handler", hc.Handler).Str("when", string(when)).Msg("Skipping hook handler not configured to run now")
log.Debug().Str(handlerLogKey, hc.Handler).Str("when", string(when)).Msg("Skipping hook handler not configured to run now")
continue
}

handler, ok := handlers[hc.Handler]
if !ok {
log.Warn().Str("handler", hc.Handler).Msg("Skipping unknown hook handler")
log.Warn().Str(handlerLogKey, hc.Handler).Msg("Skipping unknown hook handler")
continue
}

log.Debug().Str(handlerLogKey, hc.Handler).Interface("args", hc.Args).Msg("Running hook handler")

err := handler.Run(l.repository, u, config, launchType, hc.Args)
if err != nil {
log.Error().Err(err).Str("handler", hc.Handler).Msg("Hook handler execution failed")
log.Error().Err(err).Str(handlerLogKey, hc.Handler).Msg("Hook handler execution failed")
if hc.ExitOnError {
return err
}
Expand Down

0 comments on commit cae14d5

Please sign in to comment.