Repository: logging-log4j2
Updated Branches:
  refs/heads/master b9e416a97 -> 1b1bccc42


AsyncLoggerConfig optimization

AsyncLoggerConfig behaves exactly like a standard LoggerConfig
when no appenders are present. This potentially avoids unnecessarily
adding events to the background thread when an AsyncLoggerConfig
is used to set level without adding appenders directly.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1b1bccc4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1b1bccc4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1b1bccc4

Branch: refs/heads/master
Commit: 1b1bccc4241daaac57f9dce0e15195634dc40c00
Parents: b9e416a
Author: Carter Kozak <cko...@apache.org>
Authored: Sun Jun 10 22:25:41 2018 -0400
Committer: Carter Kozak <cko...@apache.org>
Committed: Tue Jun 12 07:27:00 2018 -0400

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/AsyncLoggerConfig.java  | 9 ++++++++-
 .../org/apache/logging/log4j/core/config/LoggerConfig.java  | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b1bccc4/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
index f32f0a7..06d219a 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
@@ -87,7 +87,14 @@ public class AsyncLoggerConfig extends LoggerConfig {
     }
 
     protected void log(final LogEvent event, final LoggerConfigPredicate 
predicate) {
-        if (predicate == LoggerConfigPredicate.ALL && 
ASYNC_LOGGER_ENTERED.get() == null) { // See LOG4J2-2301
+        // See LOG4J2-2301
+        if (predicate == LoggerConfigPredicate.ALL &&
+                ASYNC_LOGGER_ENTERED.get() == null &&
+                // Optimization: AsyncLoggerConfig is identical to LoggerConfig
+                // when no appenders are present. Avoid splitting for 
synchronous
+                // and asynchronous execution paths until encountering an
+                // AsyncLoggerConfig with appenders.
+                hasAppenders()) {
             // This is the first AsnycLoggerConfig encountered by this LogEvent
             ASYNC_LOGGER_ENTERED.set(Boolean.TRUE);
             try {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1b1bccc4/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index d3bb03a..092c3a2 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -565,6 +565,10 @@ public class LoggerConfig extends AbstractFilterable {
         return Boolean.parseBoolean(includeLocationConfigValue);
     }
 
+    protected final boolean hasAppenders() {
+        return !appenders.isEmpty();
+    }
+
     /**
      * The root Logger.
      */

Reply via email to