Skip to content

Commit

Permalink
fix: log fields
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Mar 8, 2024
1 parent b45f2c8 commit 4850fce
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions integration/watermill/keel/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func SubscriberWithLogger(fields ...zap.Field) SubscriberOption {
return func(o *Subscriber) {
o.middlewares = append(o.middlewares, func(next SubscriberHandler) SubscriberHandler {
return func(l *zap.Logger, r *http.Request, event *mpv2.Event) error {
fields = append(fields, zap.String("event_name", mp.GetDefault(event.EventName, "-").String()))
fields := append(fields, zap.String("event_name", mp.GetDefault(event.EventName, "-").String()))
if labeler, ok := keellog.LabelerFromRequest(r); ok {
labeler.Add(fields...)
}
Expand Down Expand Up @@ -101,9 +101,6 @@ func NewSubscriber(l *zap.Logger, opts ...SubscriberOption) *Subscriber {
func (s *Subscriber) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var values url.Values

// local logger
l := s.l

switch r.Method {
case http.MethodGet:
values = r.URL.Query()
Expand Down Expand Up @@ -132,14 +129,14 @@ func (s *Subscriber) ServeHTTP(w http.ResponseWriter, r *http.Request) {
values = r.URL.Query()
}
default:
keelhttputils.ServerError(l, w, r, http.StatusMethodNotAllowed, errors.New(http.StatusText(http.StatusMethodNotAllowed)))
keelhttputils.ServerError(s.l, w, r, http.StatusMethodNotAllowed, errors.New(http.StatusText(http.StatusMethodNotAllowed)))
return
}

// unmarshal event
var event *mpv2.Event
if err := mpv2.Decode(values, &event); err != nil {
keelhttputils.InternalServerError(l, w, r, errors.Wrap(err, "failed to marshal url values"))
keelhttputils.InternalServerError(s.l, w, r, errors.Wrap(err, "failed to marshal url values"))
return
}

Expand All @@ -150,8 +147,8 @@ func (s *Subscriber) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// run handler
if err := next(l, r, event); err != nil {
keelhttputils.InternalServerError(l, w, r, err)
if err := next(s.l, r, event); err != nil {
keelhttputils.InternalServerError(s.l, w, r, err)
return
}
}
Expand Down

0 comments on commit 4850fce

Please sign in to comment.