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)
- id: Hook Id
- levels: logrus.Levels supported by the hook
- formatter: logrus.Formatter used by the hook
- brokers: Kafka brokers
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"},
)
Create a logrus.Logger
For example:
logger := logrus.New()
logger.Hooks.Add(hook)
For only one topic pass the Kafka topic name as the Id.
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