From 432a4e509853efcb59853177bd03fdf7a3351723 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Wed, 27 Feb 2019 14:05:05 -0600 Subject: [PATCH] [LOGMGR-239] Add level check to queue replay Co-authored-by: David M. Lloyd --- .../logmanager/handlers/DelayedHandler.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jboss/logmanager/handlers/DelayedHandler.java b/core/src/main/java/org/jboss/logmanager/handlers/DelayedHandler.java index 7f8089f6..ba44bfd5 100644 --- a/core/src/main/java/org/jboss/logmanager/handlers/DelayedHandler.java +++ b/core/src/main/java/org/jboss/logmanager/handlers/DelayedHandler.java @@ -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; @@ -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 @@ -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); } }