-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLOUDTRUST-5178] Update Sarama lib + add sarama logger (#124)
* [CLOUDTRUST-5178] Update Sarama lib + add sarama logger + Force number of digit for id generated
- Loading branch information
Showing
12 changed files
with
189 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package events | ||
|
||
//go:generate mockgen --build_flags=--mod=mod -destination=./mock/sarama.go -package=mock -mock_names=SyncProducer=SyncProducer github.com/Shopify/sarama SyncProducer | ||
//go:generate mockgen --build_flags=--mod=mod -destination=./mock/sarama.go -package=mock -mock_names=SyncProducer=SyncProducer github.com/IBM/sarama SyncProducer | ||
//go:generate mockgen --build_flags=--mod=mod -destination=./mock/log.go -package=mock -mock_names=Logger=Logger github.com/cloudtrust/common-service/v2/log Logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package events | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log" | ||
|
||
"github.com/IBM/sarama" | ||
cloudtrust_log "github.com/cloudtrust/common-service/v2/log" | ||
) | ||
|
||
func NewSaramaLogger(logger cloudtrust_log.Logger, enabled bool) sarama.StdLogger { | ||
if enabled { | ||
return log.New(&cloudtrustLoggerWrapper{logger}, "[Sarama] ", log.LstdFlags) | ||
} | ||
return log.New(io.Discard, "[Sarama] ", log.LstdFlags) | ||
} | ||
|
||
type cloudtrustLoggerWrapper struct { | ||
logger cloudtrust_log.Logger | ||
} | ||
|
||
func (c *cloudtrustLoggerWrapper) Write(p []byte) (n int, err error) { | ||
c.logger.Info(context.Background(), "msg", string(p), "tag", "sarama") | ||
return len(p), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package events | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cloudtrust/common-service/v2/events/mock" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestWrite(t *testing.T) { | ||
var mockCtrl = gomock.NewController(t) | ||
defer mockCtrl.Finish() | ||
logger := mock.NewLogger(mockCtrl) | ||
|
||
writer := cloudtrustLoggerWrapper{ | ||
logger: logger, | ||
} | ||
test := "test" | ||
logger.EXPECT().Info(gomock.Any(), "msg", test, "tag", "sarama") | ||
|
||
writer.Write([]byte(test)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.