From e1a3d8c289488efaa7f62c8a6df99b0a1897b6a7 Mon Sep 17 00:00:00 2001 From: Guy Baron Date: Thu, 4 Jul 2019 19:37:17 +0300 Subject: [PATCH 1/3] fixed documentation error --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b47b03..4100e8a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Planned: 1) Deduplication of inbound messages ## Stable release -the v1.x branch contains the latest stable releases of grabbit and one should track that branch to get point and minor release updates. +the v1.x branch contains the latest stable releases of grabbit and one should track that branch to get point and minor release updates. ## Supported transactional resources 1) MySql > 8.0 (InnoDB) @@ -79,7 +79,7 @@ Register a command handler handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error - cmd, ok := message.Payload.(SomeCommand) + cmd, ok := message.Payload.(*SomeCommand) if ok { fmt.Printf("handler invoked with message %v", cmd) return nil @@ -96,7 +96,7 @@ Register an event handler eventHandler := func(invocation gbus.Invocation, message *gbus.BusMessage) { - evt, ok := message.Payload.(SomeEvent) + evt, ok := message.Payload.(*SomeEvent) if ok { fmt.Printf("handler invoked with event %v", evt) return nil From dfe0ce47ae1d06c33518e450d1c0ccd476c61511 Mon Sep 17 00:00:00 2001 From: Guy Baron Date: Thu, 4 Jul 2019 19:38:04 +0300 Subject: [PATCH 2/3] added structured logging to main readme.md file --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4100e8a..3003d9d 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ A lightweight transactional message bus on top of RabbitMQ supporting: 4) Publisher confirms 5) [Reliable messaging](https://github.com/wework/grabbit/blob/master/docs/OUTBOX.md) and local service transactivity via Transaction Outbox pattern 6) Deadlettering +7) Structured logging Planned: From f402f8b5e56e9fcc7ee2dfc183a2509e5f6eafd9 Mon Sep 17 00:00:00 2001 From: Guy Baron Date: Thu, 4 Jul 2019 19:51:38 +0300 Subject: [PATCH 3/3] added deatils on logging with in grabbit to documentation --- README.md | 4 ++-- docs/LOGGING.md | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 docs/LOGGING.md diff --git a/README.md b/README.md index 3003d9d..bcfcdab 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ A lightweight transactional message bus on top of RabbitMQ supporting: 4) Publisher confirms 5) [Reliable messaging](https://github.com/wework/grabbit/blob/master/docs/OUTBOX.md) and local service transactivity via Transaction Outbox pattern 6) Deadlettering -7) Structured logging +7) [Structured logging](https://github.com/wework/grabbit/blob/master/docs/LOGGING.md) Planned: @@ -79,7 +79,7 @@ Register a command handler ```Go -handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error +handler := func(invocation gbus.Invocation, message *gbus.BusMessage) error{ cmd, ok := message.Payload.(*SomeCommand) if ok { fmt.Printf("handler invoked with message %v", cmd) diff --git a/docs/LOGGING.md b/docs/LOGGING.md new file mode 100644 index 0000000..c5d42b8 --- /dev/null +++ b/docs/LOGGING.md @@ -0,0 +1,22 @@ +# Logging + +grabbit supports structured logging via the [logrus](https://github.com/sirupsen/logrus) logging package. +The logger is accessible to message handlers via the past in invocation instance. + +```go + +func SomeHandler(invocation gbus.Invocation, message *gbus.BusMessage) error{ + invocation.Log().WithField("name", "rhinof").Info("handler invoked") + return nil + } + +``` + +grabbit will create a default instance of logrus FieldLogger if no such logger is set when the bus is created. +In order to set a custom logger when creating the bus you need to call the Builder.WithLogger method passing it +a logrus.FieldLogger instance. + +```go + + +```