Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ protected void append(Event event) {
// Log warning if we had drop before
//
long consecutiveDropped = this.consecutiveDroppedCount.get();
if (consecutiveDropped != 0 && this.consecutiveDroppedCount.compareAndSet(consecutiveDropped, 0L)) {
if (consecutiveDropped != 0 && this.consecutiveDroppedCount.compareAndSet(consecutiveDropped, 0L) && this.droppedWarnFrequency != 0) {
addWarn("Dropped " + consecutiveDropped + " total events due to ring buffer at max capacity [" + this.ringBufferSize + "]");
}

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

Expand Down Expand Up @@ -807,8 +807,7 @@ public boolean isAddDefaultStatusListener() {
public void setAddDefaultStatusListener(boolean addDefaultStatusListener) {
this.addDefaultStatusListener = addDefaultStatusListener;
}



private static boolean isPowerOfTwo(int x) {
/* First x in the below expression is for the case when x is 0 */
return x != 0 && ((x & (x - 1)) == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,48 @@ public void testEventDroppedWhenFull() throws Exception {
eventHandlerWaiter.countDown();
}
}




@Test
public void testDisableLoggedDroppedEvents() throws Exception {
final CountDownLatch eventHandlerWaiter = new CountDownLatch(1);
TestEventHandler eventHandler = new TestEventHandler(eventHandlerWaiter);

appender.setDroppedWarnFrequency(0); // disable logging dropped events
appender.setRingBufferSize(1);
appender.setAppendTimeout(toLogback(Duration.ZERO)); // no timeout - drop when full
appender.setEventHandler(eventHandler);
appender.start();

/*
* First event blocks the ring buffer until eventHandlerWaiter is released
*/
appender.append(event1);
await().until(() -> eventHandlerWaiter.getCount() == 1); // wait until the handler is invoked before going any further

/*
* RingBuffer is full - second event is dropped and not logged
*/
appender.append(event2);

/*
* Failed to append event...
*/
verify(listener).eventAppendFailed(eq(appender), eq(event2), any());

/*
* Unblock the eventHandlerWaiter
*/
eventHandlerWaiter.countDown();

/*
* Last event would have trigger another log event.
*/
appender.append(event1);

assertThat(statusManager.getCopyOfStatusList()).hasSize(0);
}

@SuppressWarnings("unchecked")
@Test
public void testEventHandlerThrowsException() throws Exception {
Expand Down
Loading