英文:
Kafka logs in go service
问题
我需要用于调试的Kafka消费者日志。我按照以下步骤进行操作:
chanLogs := make(chan confluentkafka.LogEvent)
go func() {
for {
logEv := <-chanLogs
logger.Debug("KAFKA: " + logEv.String())
}
}()
configMap["go.logs.channel.enable"] = true
configMap["go.logs.channel"] = chanLogs
consumer, err := confluentkafka.NewConsumer(&configMap)
err := consumer.SubscribeTopics(Topics, nil)
但是我从来没有得到过一行日志。我尝试使用kafka chan (consumer.Logs()
),结果也是一样。我做错了什么?
更新
在初始帖子中,我错误地设置了参数名称。正确的参数名称是go.logs.channel.enable
。但有时这仍然不起作用。
英文:
I need kafka consumer logs for debug. I do the following:
chanLogs := make(chan confluentkafka.LogEvent)
go func() {
for {
logEv := <-chanLogs
logger.Debug("KAFKA: " + logEv.String())
}
}()
configMap["go.logs.channel.enable"] = true
configMap["go.logs.channel"] = chanLogs
consumer, err := confluentkafka.NewConsumer(&configMap)
err := consumer.SubscribeTopics(Topics, nil)
And I never get a line. I tried it with kafka chan (consumer.Logs()
) with the same result. What I do wrong?
UPD
In initial post I wrongfully set parameter name. The correct one is go.logs.channel.enable
. But sometimes this still don't work.
答案1
得分: 1
根据文档的描述,你应该启用该功能:
go.logs.channel (chan kafka.LogEvent, nil) - 将日志转发到应用程序提供的通道,而不是 Logs()。需要设置 go.logs.channel.enable=true。
所以你需要修改你的代码如下:
configMap["go.logs.channel"] = chanLogs
configMap["go.logs.channel.enable"] = true
consumer, err := confluentkafka.NewConsumer(&configMap)
英文:
As described in the doc, you should enable that feature:
go.logs.channel.enable (bool, false) - Forward log to Logs() channel.
go.logs.channel (chan kafka.LogEvent, nil) - Forward logs to application-provided channel instead of Logs(). Requires go.logs.channel.enable=true.
So change your code like:
configMap["go.logs.channel"] = chanLogs
configMap["go.logs.channel.enable"] = true
consumer, err := confluentkafka.NewConsumer(&configMap)
答案2
得分: 1
解决方案是添加以下代码:
configMap["debug"] = "all"
我在这里找到了它:链接
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论