简体   繁体   English

Kafka登录go服务

[英]Kafka logs in go service

I need kafka consumer logs for debug.我需要 kafka 消费者日志进行调试。 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.我用 kafka chan ( consumer.Logs() )尝试了它,结果相同。 What I do wrong?我做错了什么?

UPD In initial post I wrongfully set parameter name. UPD在最初的帖子中,我错误地设置了参数名称。 The correct one is go.logs.channel.enable .正确的是go.logs.channel.enable But sometimes this still don't work.但有时这仍然不起作用。

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)

See also in the doc or in the sample on the code repo here另请参阅文档或代码仓库的示例here

The solution was to add解决方案是添加

    configMap["debug"] = "all"

I found it here我在这里找到了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM