Skip to content

Commit

Permalink
use structured logging for executed steps
Browse files Browse the repository at this point in the history
  • Loading branch information
foosinn committed Mar 22, 2022
1 parent 5ebec78 commit 88ffcbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func runner() GuardFunc {
}

err = cmd.Wait()
log.Debug().Err(err).Msg("executed in runner")
log.Debug().Err(err).Str("middleware", "runner").Msg("executed")

if err != nil {
switch casted := err.(type) {
Expand Down
23 changes: 12 additions & 11 deletions middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func setupLogs(g GuardFunc) GuardFunc {
defer errFile.Close()

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in setupLogs")
log.Debug().Err(err).Str("middleware", "setupLogs").Msg("executed")

if err != nil {
n, err := combined.WriteTo(errFile)
Expand All @@ -54,7 +54,7 @@ func writeSyslog(g GuardFunc) GuardFunc {
defer slog.Close()
cr.Status.Combined = io.MultiWriter(slog, cr.Status.Combined)
err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in writeSyslog")
log.Debug().Err(err).Str("middleware", "writeSyslog").Msg("executed")
return err
}
}
Expand All @@ -68,7 +68,7 @@ func insertUUID(g GuardFunc) GuardFunc {
combined := newUUIDPrefixer(cr.Status.Combined)
cr.Status.Combined = combined
err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in insertUUID")
log.Debug().Err(err).Str("middleware", "insertUUID").Msg("executed")
return err
}
}
Expand All @@ -80,7 +80,7 @@ func combineLogs(g GuardFunc) GuardFunc {
cr.Status.Stdout = io.MultiWriter(cr.Status.Stdout, combined)
cr.Status.Stderr = io.MultiWriter(cr.Status.Stderr, combined)
err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in combineLogs")
log.Debug().Err(err).Str("middleware", "combineLogs").Msg("executed")
return err
}
}
Expand All @@ -99,7 +99,7 @@ func headerize(g GuardFunc) GuardFunc {
}

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in headerize")
log.Debug().Err(err).Str("middleware", "headerize").Msg("executed")

end := time.Now()
if !cr.ErrFileQuiet {
Expand Down Expand Up @@ -140,7 +140,7 @@ func lockfile(g GuardFunc) GuardFunc {
}

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in lockfile")
log.Debug().Err(err).Str("middleware", "lockfile").Msg("executed")

return err
}
Expand All @@ -151,13 +151,14 @@ func sentryHandler(g GuardFunc) GuardFunc {
return func(ctx context.Context, cr *CmdRequest) (err error) {
reporter, reporterErr := newReporter(cr)
if reporterErr != nil {
log.Debug().Err(reporterErr).Msg("sentry is disabled")
return g(ctx, cr)
}

cr.Reporter = reporter

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in sentryHandler")
log.Debug().Err(err).Str("middleware", "sentryHandler").Msg("executed")

return reporter.Finish(err)
}
Expand All @@ -172,7 +173,7 @@ func quietIgnore(g GuardFunc) GuardFunc {
}

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in quietIgnore")
log.Debug().Err(err).Str("middleware", "quietIgnore").Msg("executed")

if quiet {
return nil
Expand All @@ -190,7 +191,7 @@ func validateStderr(g GuardFunc) GuardFunc {
cr.Status.Stderr = wc

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in validateStderr")
log.Debug().Err(err).Str("middleware", "validateStderr").Msg("executed")

if err != nil {
return err
Expand Down Expand Up @@ -227,7 +228,7 @@ func validateStdout(g GuardFunc) GuardFunc {
})

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in validateStdout")
log.Debug().Err(err).Str("middleware", "validateStdout").Msg("executed")

if err != nil {
return
Expand All @@ -251,7 +252,7 @@ func timeout(g GuardFunc) GuardFunc {
defer cancel()

err = g(ctx, cr)
log.Debug().Err(err).Msg("executed in timeout")
log.Debug().Err(err).Str("middleware", "timeout").Msg("executed")

if err != nil {
if err := ctx.Err(); err != nil {
Expand Down

0 comments on commit 88ffcbe

Please sign in to comment.