-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-6167] use go-logging for sarama logging
- sarama kafka client library will log to a go-logging logger with id: orderer/consensus/kafka/sarama. - the logger can be enabled via Kafka.Verbose config or by explicitly setting to DEBUG in the log specification string. Change-Id: Ieb91ef06a7d7b8587b711439d26e116d12260dd9 Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
- Loading branch information
Luis Sanchez
committed
Sep 15, 2017
1 parent
40e41a5
commit d06c012
Showing
6 changed files
with
83 additions
and
29 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
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,56 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package kafka | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Shopify/sarama" | ||
"github.com/hyperledger/fabric/common/flogging" | ||
logging "github.com/op/go-logging" | ||
) | ||
|
||
const ( | ||
pkgLogID = "orderer/consensus/kafka" | ||
saramaLogID = pkgLogID + "/sarama" | ||
) | ||
|
||
var logger *logging.Logger | ||
|
||
// init initializes the package logger | ||
func init() { | ||
logger = flogging.MustGetLogger(pkgLogID) | ||
} | ||
|
||
// init initializes the samara logger | ||
func init() { | ||
loggingProvider := flogging.MustGetLogger(saramaLogID) | ||
loggingProvider.ExtraCalldepth = 3 | ||
sarama.Logger = &saramaLoggerImpl{ | ||
logger: loggingProvider, | ||
} | ||
} | ||
|
||
type saramaLoggerImpl struct { | ||
logger *logging.Logger | ||
} | ||
|
||
func (l saramaLoggerImpl) Print(args ...interface{}) { | ||
l.print(fmt.Sprint(args...)) | ||
} | ||
|
||
func (l saramaLoggerImpl) Printf(format string, args ...interface{}) { | ||
l.print(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (l saramaLoggerImpl) Println(args ...interface{}) { | ||
l.print(fmt.Sprintln(args...)) | ||
} | ||
|
||
func (l saramaLoggerImpl) print(message string) { | ||
l.logger.Debug(message) | ||
} |
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,18 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package kafka | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Shopify/sarama" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoggerInit(t *testing.T) { | ||
assert.IsType(t, &saramaLoggerImpl{}, sarama.Logger, "Sarama logger not properly initialized") | ||
} |