Skip to content

Commit

Permalink
events: Add debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Apr 27, 2024
1 parent 1b9042b commit ba58114
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/caddyevents/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) E
return nil, false
})

logger.Debug("event", zap.Any("data", e.Data))
logger = logger.With(zap.Any("data", e.Data))

logger.Debug("event")

// invoke handlers bound to the event by name and also all events; this for loop
// iterates twice at most: once for the event name, once for "" (all events)
Expand All @@ -282,6 +284,12 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) E
default:
}

// this log can be a useful sanity check to ensure your handlers are in fact being invoked
// (see https://github.com/mholt/caddy-events-exec/issues/6)
logger.Debug("invoking subscribed handler",
zap.String("subscribed_to", eventName),
zap.Any("handler", handler))

if err := handler.Handle(ctx, e); err != nil {
aborted := errors.Is(err, ErrAborted)

Expand Down

0 comments on commit ba58114

Please sign in to comment.