From 8f2199a8e30c55ebd9dbdad5c57bf288a8809f08 Mon Sep 17 00:00:00 2001 From: Rob Hansen Date: Thu, 24 Feb 2022 10:23:35 -0800 Subject: [PATCH] add logging section to readme (#853) * add logging section to readme --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index c7c8ada31..3ac4d5043 100644 --- a/README.md +++ b/README.md @@ -669,6 +669,45 @@ if err := r.Close(); err != nil { } ``` + +## Logging + +For visiblity into the operations of the Reader/Writer types, configure a logger on creation. + + +### Reader + +```go +func logf(msg string, a ...interface{}) { + fmt.Println(msg, a...) +} + +r := kafka.NewReader(kafka.ReaderConfig{ + Brokers: []string{"localhost:9092"}, + Topic: "my-topic1", + Partition: 0, + Logger: kafka.LoggerFunc(logf), + ErrorLogger: kafka.LoggerFunc(logf), +}) +``` + +### Writer + +```go +func logf(msg string, a ...interface{}) { + fmt.Println(msg, a...) +} + +w := &kafka.Writer{ + Addr: kafka.TCP("localhost:9092"), + Topic: "topic", + Logger: kafka.LoggerFunc(logf), + ErrorLogger: kafka.LoggerFunc(logf), +} +``` + + + ## Testing Subtle behavior changes in later Kafka versions have caused some historical tests to break, if you are running against Kafka 2.3.1 or later, exporting the `KAFKA_SKIP_NETTEST=1` environment variables will skip those tests.