Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add protection against log queue overruns
Browse files Browse the repository at this point in the history
dmlloyd committed Mar 10, 2021
1 parent efcf6cb commit 8faa8a1
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.logging.ErrorManager;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Logger;
@@ -36,10 +37,19 @@ public class QuarkusDelayedHandler extends ExtHandler {

private final Deque<ExtLogRecord> logRecords = new ArrayDeque<>();

private final int queueLimit;
private volatile boolean buildTimeLoggingActivated = false;
private volatile boolean activated = false;
private volatile boolean callerCalculationRequired = false;

public QuarkusDelayedHandler() {
this(4000);
}

public QuarkusDelayedHandler(final int queueLimit) {
this.queueLimit = queueLimit;
}

@Override
protected void doPublish(final ExtLogRecord record) {
// If activated just delegate
@@ -53,6 +63,11 @@ protected void doPublish(final ExtLogRecord record) {
publishToNestedHandlers(record);
super.doPublish(record);
} else {
// Determine whether the queue was overrun
if (logRecords.size() >= queueLimit) {
reportError("The delayed handler's queue was overrun and log record(s) were lost. Did you forget to configure logging?", null, ErrorManager.WRITE_FAILURE);
return;
}
// Determine if we need to calculate the caller information before we queue the record
if (isCallerCalculationRequired()) {
// prepare record to move to another thread

0 comments on commit 8faa8a1

Please sign in to comment.