pulsar-client-cpp icon indicating copy to clipboard operation
pulsar-client-cpp copied to clipboard

how can close pulsar logs

Open frkn4129 opened this issue 1 year ago • 1 comments

I am using Pulsar Cpp in my project but it produces pulsar INFO logs roughly every 10 minutes. How can I close INFO logs from Pulsar? Example Log:

INFO [139790546368256] ProducerStatsImpl:87 | Producer [persistent://public/default/test_fm_2, ] , ProducerStatsImpl (numMsgsSent_ = 1151, numBytesSent_ = 99461243, sendMap_ = {[Key: Ok, Value: 1151], }, latencyAccumulator_ = Latencies [ 50pct: 2.70125ms, 90pct: 91.4338ms, 99pct: 353.278ms, 99.9pct: 540.775ms], totalMsgsSent_ = 1151, totalBytesSent_ = 99461243, totalAcksReceived_ = , totalSendMap_ = {[Key: Ok, Value: 1151], }, totalLatencyAccumulator_ = Latencies [ 50pct: 2.70125ms, 90pct: 91.4338ms, 99pct: 353.278ms, 99.9pct: 540.775ms])

frkn4129 avatar Feb 01 '24 13:02 frkn4129

First, these logs come from the stats timer. You can disable the stats by configuring the stats interval with 0.

https://github.com/apache/pulsar-client-cpp/blob/c7e53acfc7c31c19ba623fed011caee3c6571a3f/include/pulsar/ClientConfiguration.h#L293

Second, if you really want to disable the INFO logs rather than the stats timer. You can configure a customized logger.

https://github.com/apache/pulsar-client-cpp/blob/c7e53acfc7c31c19ba623fed011caee3c6571a3f/include/pulsar/ClientConfiguration.h#L188

There are two built-in loggers:

  • https://github.com/apache/pulsar-client-cpp/blob/main/include/pulsar/ConsoleLoggerFactory.h
  • https://github.com/apache/pulsar-client-cpp/blob/main/include/pulsar/FileLoggerFactory.h

For simplicity, if you still want to print logs to console and just change the log level to warn, here is an example.

    ClientConfiguration conf;
    conf.setLogger(new ConsoleLoggerFactory(Logger::LEVEL_WARN));
    Client client("pulsar://localhost:6650", conf);

BewareMyPower avatar Feb 04 '24 03:02 BewareMyPower