-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
31 lines (27 loc) · 810 Bytes
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package middleware
import (
"time"
"github.com/sirupsen/logrus"
"go.eloylp.dev/goomerang/message"
)
// Logger allows passing a customized logrus logger. It will
// log the main attributes of all messages.
//
// It will only log messages in Debug level.
func Logger(logger logrus.FieldLogger) message.Middleware {
return func(h message.Handler) message.Handler {
return message.HandlerFunc(func(s message.Sender, msg *message.Message) {
sender := NewSender(s)
start := time.Now()
h.Handle(sender, msg)
duration := time.Since(start)
logger.WithFields(logrus.Fields{
"kind": msg.Metadata.Kind,
"metadata": msg.Metadata,
"headers": msg.Header,
"processingTime": duration,
"payload": msg.Payload,
}).Debug("message processed")
})
}
}