Skip to content

Commit

Permalink
chore(pkg/runner): improved logging system
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
  • Loading branch information
leogr committed Apr 10, 2020
1 parent d236766 commit 994d5cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/runner/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type helper struct {
name string
runner *Runner
log *logger.Entry
hasLog bool
builder *resource.Builder
cleanup func()
}

func (h *helper) Log() *logger.Entry {
h.hasLog = true
return h.log
}

Expand All @@ -42,8 +44,15 @@ func (h *helper) Cleanup(f func(), args ...interface{}) {
if oldCleanup != nil {
defer oldCleanup()
}
args = append([]interface{}{"clenaup "}, args...)
h.Log().Info(args...)
log := h.Log()
if len(args) > 0 {
if l, ok := args[0].(*logger.Entry); ok {
log = l
args = args[1:]
}
}
args = append([]interface{}{"cleanup "}, args...)
log.Info(args...)
f()
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (r *Runner) trigger(n string, f events.Action) (cleanup func(), err error)
fields["as"] = r.alias
}
log := r.log.WithFields(fields)
log.Info("trigger")

h := &helper{
name: n,
Expand All @@ -42,6 +41,8 @@ func (r *Runner) trigger(n string, f events.Action) (cleanup func(), err error)

if err := f(h); err != nil {
log.WithError(err).Error("action error")
} else if !h.hasLog {
log.Info("action executed")
}

return h.cleanup, nil
Expand Down

0 comments on commit 994d5cf

Please sign in to comment.