Repository: logging-log4j2
Updated Branches:
  refs/heads/release-2.x 6f35cd3cc -> 2c6314394


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/2c631439
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2c631439
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2c631439

Branch: refs/heads/release-2.x
Commit: 2c63143947abb373d8268a3204bb64b6a63b6686
Parents: 6f35cd3
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:34 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/2c631439/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/2c631439/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