A logrus.Hook which sends a single log entry to multiple kafka topics simultaneously.
import lkh "github.com/gfremex/logrus-kafka-hook"
NewKafkaHook(id string, levels []logrus.Level, formatter logrus.Formatter, brokers []string) (*KafkaHook, error)
For example:
hook, err := lkh.NewKafkaHook( "kh", []logrus.Level{logrus.InfoLevel, logrus.WarnLevel, logrus.ErrorLevel}, &logrus.JSONFormatter{}, []string{"192.168.60.5:9092", "192.168.60.6:9092", "192.168.60.7:9092"}, )
For example:
logger := logrus.New()
logger.Hooks.Add(hook)
l := logger.WithField("topics", []string{"topic_1", "topic_2", "topic_3"})
The field name must be topics.
If only one topic needed, then
l := logger.WithField("topics", []string{"topic_1"})
For example:
l.Debug("This must not be logged") l.Info("This is an Info msg") l.Warn("This is a Warn msg") l.Error("This is an Error msg")
https://github.com/gfremex/logrus-kafka-hook/tree/master/examples