Kaflog is a hook for EACIIT Toolkit LogEngine to publish log information into Kafka cluster
- Initiate Log Engine
log := toolkit.NewLog(true,false,"./logs","","")
- Hook kafka log
// attach kafka publisher hook to log log.AddHook( // Host = address of web application // Topic = name of Kafka topic // Brokers = list of Kafka brokers kaflog.Hook(host, topic, brokers...), // type of log will be published to Kafka "ERROR", "WARNING")
- Run docker compose to bring up zookeeper and kafka service
cd docker MY_IP={IP} docker-compose up - Using kafkacat: create a consumer to subscribe for topic
kafkacat -C -b server1:host1,serverN:hostN -t topicname -p 0
- Test by using kafkacat to see if respective consumer subscribtion work properly
echo "Test publish kafka" | kafkacat -P -b server1:host1,serverN:hostN -t topicname -p 0
- Attach kaflog hook to Knot Web Application
// prepare log log, _ := toolkit.NewLog(true, true, "./logs", "$LOGTYPE_$DATE.log", "yyyyMMdd") // attach kafka publisher hook to log log.AddHook( // Host = address of web application // Topic = name of Kafka topic // Brokers = list of Kafka brokers kaflog.Hook(host, topic, brokers...), // type of log will be published to Kafka "ERROR", "WARNING") // attach log to knot app s := knot.NewServer().SetLogger(log)
- Run, check and monitor
KAFKA_BROKERS=server1:host1,serverN:hostN KAFKA_TOPIC=foo go run main.go