Home > Mobile >  Kafka logs in go service
Kafka logs in go service

Time:11-23

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.

CodePudding user response:

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

CodePudding user response:

The solution was to add

    configMap["debug"] = "all"

I found it here

  • Related