Skip to content

Commit

Permalink
Merge pull request #233 from dmlloyd/delayed-level-check
Browse files Browse the repository at this point in the history
[LOGMGR-239] Add level check to queue replay
  • Loading branch information
jamezp authored Feb 28, 2019
2 parents 79881d4 + 432a4e5 commit a852bea
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.LogContext;
import org.jboss.logmanager.StandardOutputStreams;
import org.jboss.logmanager.formatters.PatternFormatter;

Expand All @@ -44,6 +45,24 @@ public class DelayedHandler extends ExtHandler {
private volatile boolean activated = false;
private volatile boolean callerCalculationRequired = false;

private final LogContext logContext;

/**
* Construct a new instance.
*/
public DelayedHandler() {
this(null);
}

/**
* Construct a new instance, with the given log context used to recheck log levels on replay.
*
* @param logContext the log context to use for level checks on replay, or {@code null} for none
*/
public DelayedHandler(LogContext logContext) {
this.logContext = logContext;
}

@Override
protected void doPublish(final ExtLogRecord record) {
// If activated just delegate
Expand Down Expand Up @@ -198,8 +217,9 @@ public final boolean isActivated() {
private synchronized void activate() {
// Always attempt to drain the queue
ExtLogRecord record;
final LogContext logContext = this.logContext;
while ((record = logRecords.pollFirst()) != null) {
if (isEnabled() && isLoggable(record)) {
if (isEnabled() && isLoggable(record) && (logContext == null || logContext.getLogger(record.getLoggerName()).isLoggable(record.getLevel()))) {
publishToChildren(record);
}
}
Expand Down

0 comments on commit a852bea

Please sign in to comment.