Skip to content

Commit 8548291

Browse files
Allow setting droppedWarnFrequency=0 to disable logging dropped message warnings (#1086)
Allow setting droppedWarnFrequency=0 to disable logging dropped message warnings Setting droppedWarnFrequency=0 was intended to disable logging of dropped events. --------- Co-authored-by: Phil Clay <[email protected]>
1 parent c970c48 commit 8548291

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/main/java/net/logstash/logback/appender/AsyncDisruptorAppender.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ protected void append(Event event) {
499499
// Log warning if we had drop before
500500
//
501501
long consecutiveDropped = this.consecutiveDroppedCount.get();
502-
if (consecutiveDropped != 0 && this.consecutiveDroppedCount.compareAndSet(consecutiveDropped, 0L)) {
502+
if (consecutiveDropped != 0 && this.consecutiveDroppedCount.compareAndSet(consecutiveDropped, 0L) && this.droppedWarnFrequency != 0) {
503503
addWarn("Dropped " + consecutiveDropped + " total events due to ring buffer at max capacity [" + this.ringBufferSize + "]");
504504
}
505505

@@ -511,7 +511,7 @@ protected void append(Event event) {
511511
// Log a warning status about the failure
512512
//
513513
long consecutiveDropped = this.consecutiveDroppedCount.incrementAndGet();
514-
if ((consecutiveDropped % this.droppedWarnFrequency) == 1) {
514+
if (this.droppedWarnFrequency != 0 && (consecutiveDropped % this.droppedWarnFrequency) == 1) {
515515
addWarn("Dropped " + consecutiveDropped + " events (and counting...) due to ring buffer at max capacity [" + this.ringBufferSize + "]");
516516
}
517517

@@ -807,8 +807,7 @@ public boolean isAddDefaultStatusListener() {
807807
public void setAddDefaultStatusListener(boolean addDefaultStatusListener) {
808808
this.addDefaultStatusListener = addDefaultStatusListener;
809809
}
810-
811-
810+
812811
private static boolean isPowerOfTwo(int x) {
813812
/* First x in the below expression is for the case when x is 0 */
814813
return x != 0 && ((x & (x - 1)) == 0);

src/test/java/net/logstash/logback/appender/AsyncDisruptorAppenderTest.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,48 @@ public void testEventDroppedWhenFull() throws Exception {
200200
eventHandlerWaiter.countDown();
201201
}
202202
}
203-
204-
203+
204+
205+
@Test
206+
public void testDisableLoggedDroppedEvents() throws Exception {
207+
final CountDownLatch eventHandlerWaiter = new CountDownLatch(1);
208+
TestEventHandler eventHandler = new TestEventHandler(eventHandlerWaiter);
209+
210+
appender.setDroppedWarnFrequency(0); // disable logging dropped events
211+
appender.setRingBufferSize(1);
212+
appender.setAppendTimeout(toLogback(Duration.ZERO)); // no timeout - drop when full
213+
appender.setEventHandler(eventHandler);
214+
appender.start();
215+
216+
/*
217+
* First event blocks the ring buffer until eventHandlerWaiter is released
218+
*/
219+
appender.append(event1);
220+
await().until(() -> eventHandlerWaiter.getCount() == 1); // wait until the handler is invoked before going any further
221+
222+
/*
223+
* RingBuffer is full - second event is dropped and not logged
224+
*/
225+
appender.append(event2);
226+
227+
/*
228+
* Failed to append event...
229+
*/
230+
verify(listener).eventAppendFailed(eq(appender), eq(event2), any());
231+
232+
/*
233+
* Unblock the eventHandlerWaiter
234+
*/
235+
eventHandlerWaiter.countDown();
236+
237+
/*
238+
* Last event would have trigger another log event.
239+
*/
240+
appender.append(event1);
241+
242+
assertThat(statusManager.getCopyOfStatusList()).hasSize(0);
243+
}
244+
205245
@SuppressWarnings("unchecked")
206246
@Test
207247
public void testEventHandlerThrowsException() throws Exception {

0 commit comments

Comments
 (0)