Skip to content

Commit 605e479

Browse files
authored
L-849 Send logs in configured batches, repeat sending unsuccessful data (#18)
* Do not sent batches larger than configured batchSize to Better Stack * Repeat sending logs that were not successfully accepted by Better Stack * Accept all 2xx status codes as successful * Ensure reflushing on non-2xx status code or when queue overfilled
1 parent 6c4707a commit 605e479

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main/java/com/logtail/logback/LogtailAppender.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,24 @@ protected void flush() {
126126
if (isFlushing.getAndSet(true))
127127
return;
128128

129-
this.mustReflush = false;
129+
mustReflush = false;
130130

131131
try {
132132
int flushedSize = batch.size();
133+
if (flushedSize > batchSize) {
134+
flushedSize = batchSize;
135+
mustReflush = true;
136+
}
133137

134138
LogtailResponse response = callHttpURLConnection(flushedSize);
135139

136-
if (response.getStatus() != 202) {
140+
if (response.getStatus() >= 200 && response.getStatus() < 300) {
141+
batch.subList(0, flushedSize).clear();
142+
this.warnAboutMaxQueueSize = true;
143+
} else {
137144
errorLog.error("Error calling Better Stack : {} ({})", response.getError(), response.getStatus());
145+
mustReflush = true;
138146
}
139-
140-
batch.subList(0, flushedSize).clear();
141-
this.warnAboutMaxQueueSize = true;
142147
} catch (JsonProcessingException e) {
143148
errorLog.error("Error processing JSON data : {}", e.getMessage(), e);
144149

@@ -148,7 +153,7 @@ protected void flush() {
148153

149154
isFlushing.set(false);
150155

151-
if (this.mustReflush || batch.size() >= batchSize)
156+
if (mustReflush || batch.size() >= batchSize)
152157
flush();
153158
}
154159

0 commit comments

Comments
 (0)