Skip to content

Commit f402f8b

Browse files
author
Guy Baron
committed
added deatils on logging with in grabbit to documentation
1 parent dfe0ce4 commit f402f8b

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ A lightweight transactional message bus on top of RabbitMQ supporting:
2020
4) Publisher confirms
2121
5) [Reliable messaging](https://github.com/wework/grabbit/blob/master/docs/OUTBOX.md) and local service transactivity via Transaction Outbox pattern
2222
6) Deadlettering
23-
7) Structured logging
23+
7) [Structured logging](https://github.com/wework/grabbit/blob/master/docs/LOGGING.md)
2424

2525
Planned:
2626

@@ -79,7 +79,7 @@ Register a command handler
7979
```Go
8080

8181

82-
handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error
82+
handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error{
8383
cmd, ok := message.Payload.(*SomeCommand)
8484
if ok {
8585
fmt.Printf("handler invoked with message %v", cmd)

‎docs/LOGGING.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Logging
2+
3+
grabbit supports structured logging via the [logrus](https://github.com/sirupsen/logrus) logging package.
4+
The logger is accessible to message handlers via the past in invocation instance.
5+
6+
```go
7+
8+
func SomeHandler(invocation gbus.Invocation, message *gbus.BusMessage) error{
9+
invocation.Log().WithField("name", "rhinof").Info("handler invoked")
10+
return nil
11+
}
12+
13+
```
14+
15+
grabbit will create a default instance of logrus FieldLogger if no such logger is set when the bus is created.
16+
In order to set a custom logger when creating the bus you need to call the Builder.WithLogger method passing it
17+
a logrus.FieldLogger instance.
18+
19+
```go
20+
21+
22+
```

0 commit comments

Comments
 (0)