loki4j / loki-logback-appender

Fast and lightweight implementation of Logback appender for Grafana Loki
https://loki4j.github.io/loki-logback-appender/
BSD 2-Clause "Simplified" License
300 stars 26 forks source link

Disable INFO log if HTTP respone code 204 #190

Closed leotu closed 11 months ago

leotu commented 11 months ago

I have lots of message "<<< Batch #6ec4d447249c (4,566 bytes): Loki responded with status 204"

Unnecessary print log or reduce log level if HTTP status is 204

=> if (r.status >= 200 && r.status < 300) { ...

 private LokiResponse sendBatch(BinaryBatch batch) {
       ...
          ...
            // try to send the batch
            try {
                r = httpClient.send(batch.data);
                // exit if send is successful
                if (r.status >= 200 && r.status < 300) {
                    log.info("<<< %sBatch %s: Loki responded with status %s",
                        retry > 0 ? "Retry #" + retry + ". " : "", batch, r.status);
                    if (metrics != null) metrics.batchSent(startedNs, batch.sizeBytes);
                    return r;
                }
            } catch (Exception re) {
                e = re;
            }
...
    }
12:01:31,815 |-INFO in com.github.loki4j.client.pipeline.AsyncBufferPipeline@5080feff - <<< Batch #6ec4d447249c (4,566 bytes): Loki responded with status 204
nehaev commented 11 months ago

Hi @leotu, thanks for reporting this!

If you don't want to see such log messages, all you need is to disable verbose mode:

<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
    ...
    <verbose>false</verbose>
</appender>

Or you can simply delete verbose setting from the config as it's false by default.