You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/16 14:38:18 UTC

[01/50] logging-log4j2 git commit: Format nit.

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1278-gc-free-logger 2faae9c97 -> b6ef29324


Format nit.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: bc5a8097b2179a8023345d7099fa0dd99ecc77dc
Parents: 62f42bf
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 10:11:19 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 10:11:19 2016 -0600

----------------------------------------------------------------------
 .../org/apache/logging/log4j/test/appender/AlwaysFailAppender.java | 2 +-
 .../org/apache/logging/log4j/test/appender/DeadlockAppender.java   | 2 +-
 .../org/apache/logging/log4j/test/appender/FailOnceAppender.java   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bc5a8097/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/AlwaysFailAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/AlwaysFailAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/AlwaysFailAppender.java
index dc9047b..6d5fb11 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/AlwaysFailAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/AlwaysFailAppender.java
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
 /**
  *
  */
-@Plugin(name="AlwaysFail", category ="Core",elementType="appender",printObject=true)
+@Plugin(name="AlwaysFail", category ="Core", elementType="appender", printObject=true)
 public class AlwaysFailAppender extends AbstractAppender {
 
     private AlwaysFailAppender(final String name) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bc5a8097/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java
index 8383c50..7dd0c62 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
 /**
  *
  */
-@Plugin(name="Deadlock", category ="Core",elementType="appender",printObject=true)
+@Plugin(name="Deadlock", category ="Core", elementType="appender", printObject=true)
 public class DeadlockAppender extends AbstractAppender {
 
     private WorkerThread thread = null;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bc5a8097/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/FailOnceAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/FailOnceAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/FailOnceAppender.java
index b2e8c2a..ebe1617 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/FailOnceAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/FailOnceAppender.java
@@ -30,7 +30,7 @@ import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
 /**
  *
  */
-@Plugin(name="FailOnce", category ="Core",elementType="appender",printObject=true)
+@Plugin(name="FailOnce", category ="Core", elementType="appender", printObject=true)
 public class FailOnceAppender extends AbstractAppender {
 
     boolean fail = true;


[20/50] logging-log4j2 git commit: [LOG4J2-63] Support configuration from version 1.x log4j.properties. Complete TTCC layout.

Posted by rp...@apache.org.
[LOG4J2-63] Support configuration from version 1.x log4j.properties.
Complete TTCC layout.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 3245c20c822da109c51ab58f2f1ace90e150287f
Parents: 0d2cfbe
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 09:50:00 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 09:50:00 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/log4j/config/Log4j1ConfigurationFactory.java   | 2 +-
 .../org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3245c20c/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index fc07c1c..578b2ab 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -122,7 +122,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
             }
             case "org.apache.log4j.TTCCLayout": {
                 // TODO We do not have a %d for the time since the start of the app?
-                appenderBuilder.add(newPatternLayout(builder, "%d{UNIX_MILLIS} [%threadName] %level %logger - %m%n"));
+                appenderBuilder.add(newPatternLayout(builder, "%relative [%threadName] %level %logger - %m%n"));
                 break;
             }
             case "org.apache.log4j.HTMLLayout": {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3245c20c/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 3212db0..4d637b2 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -77,7 +77,7 @@ public class Log4j1ConfigurationFactoryTest {
     @Test
     public void testConsoleTtccLayout() throws Exception {
         final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-TTCCLayout.properties");
-        Assert.assertEquals("%d{UNIX_MILLIS} [%threadName] %level %logger - %m%n", layout.getConversionPattern());
+        Assert.assertEquals("%relative [%threadName] %level %logger - %m%n", layout.getConversionPattern());
     }
 
     @Test


[14/50] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by rp...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 9a01ec66e78a5f3780a46be675616ecd462add44
Parents: 9371266 3542dae
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 00:20:31 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 00:20:31 2016 -0800

----------------------------------------------------------------------
 .../log4j/core/async/AsyncLoggerConfigDisruptor.java |  4 ++--
 .../log4j/core/async/AsyncLoggerDisruptor.java       |  4 ++--
 .../appender/rolling/RollingAppenderSizeTest.java    | 15 +++++----------
 .../logging/log4j/web/Log4jWebInitializerImpl.java   |  5 +++--
 src/changes/changes.xml                              |  3 +++
 5 files changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------



[42/50] logging-log4j2 git commit: LOG4J2-1296 made initial and max StringBuilder size configurable, changed default of max to 518

Posted by rp...@apache.org.
LOG4J2-1296 made initial and max StringBuilder size configurable, changed default of max to 518


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: b334215219f2fe853ce2bce2ab2366bc744a6106
Parents: 50c7683
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 08:34:19 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 08:34:19 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/RingBufferLogEvent.java    |  9 +++++++--
 src/site/xdoc/manual/configuration.xml.vm               | 12 ++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b3342152/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index e4c135a..d4669f7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ReusableMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.Strings;
 
 import com.lmax.disruptor.EventFactory;
@@ -46,8 +47,12 @@ public class RingBufferLogEvent implements LogEvent {
     public static final Factory FACTORY = new Factory();
 
     private static final long serialVersionUID = 8462119088943934758L;
-    private static final int INITIAL_REUSABLE_MESSAGE_SIZE = 128;
-    private static final int MAX_REUSABLE_MESSAGE_SIZE = 128 * 2 + 2; // resized once from 128 (s=s*2+2)
+    private static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
+    private static final int MAX_REUSABLE_MESSAGE_SIZE = size("log4j.maxReusableMsgSize", (128 * 2 + 2) * 2 + 2);
+
+    private static int size(final String property, final int defaultValue) {
+        return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
+    }
 
     /**
      * Creates the events that will be put in the RingBuffer.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b3342152/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index f1e72f0..18d53b2 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -1903,6 +1903,18 @@ public class AwesomeTest {
     <td>org.apache.logging.log4j.message. DefaultFlowMessageFactory</td>
     <td>Default flow message factory used by Loggers.</td>
   </tr>
+  <tr>
+    <td>log4j.initialReusableMsgSize</td>
+    <td>128</td>
+    <td>In GC-free mode, this property determines the initial size of the reusable StringBuilders where the message
+     text is formatted and potentially passed to background threads.</td>
+  </tr>
+  <tr>
+    <td>log4j.maxReusableMsgSize</td>
+    <td>518</td>
+    <td>In GC-free mode, this property determines the maximum size of the reusable StringBuilders where the message
+     text is formatted and potentially passed to background threads.</td>
+  </tr>
 </table>
 
         </subsection>


[24/50] logging-log4j2 git commit: Re-implement CompositeFilter to be backed by a Filter[] instead of an ArrayList for performance. Internally, we now traverse the array as a primitive with [] instead of using a new Iterator each time the filters

Posted by rp...@apache.org.
Re-implement CompositeFilter to be backed by a Filter[] instead of an
ArrayList<Filter> for performance. Internally, we now traverse the array
as a primitive with [] instead of using a new Iterator each time the
filters need to be traversed. Note: I have a use case where the internal
list was always empty, which meant an iterator was always created, when
for example, Logger.isTraceEnabled() was called. After a couple of
million times calling isTraceEnabled(), it adds up. Now, the array is
not traversed since it is since of length 0. This is means one less
object generated per call to isTraceEnabled() and thrown away (the
iterator) when a config has an empty Filters section (because child in
it is commented out).

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 3761dba60f3f498f8691f59e772a2cb4d9be2928
Parents: b74ece8
Author: ggregory <gg...@apache.org>
Authored: Fri Mar 11 17:05:21 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Fri Mar 11 17:05:21 2016 -0800

----------------------------------------------------------------------
 .../log4j/core/filter/CompositeFilter.java      |  76 ++++----
 .../log4j/core/util/ObjectArrayIterator.java    | 178 +++++++++++++++++++
 .../log4j/core/CustomLevelsWithFiltersTest.java |   6 +-
 3 files changed, 223 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3761dba6/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/CompositeFilter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/CompositeFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/CompositeFilter.java
index 5fe084c..7a6efbc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/CompositeFilter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/CompositeFilter.java
@@ -16,9 +16,7 @@
  */
 package org.apache.logging.log4j.core.filter;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -32,6 +30,7 @@ import org.apache.logging.log4j.core.config.Node;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.util.ObjectArrayIterator;
 import org.apache.logging.log4j.message.Message;
 
 /**
@@ -40,18 +39,15 @@ import org.apache.logging.log4j.message.Message;
 @Plugin(name = "filters", category = Node.CATEGORY, printObject = true)
 public final class CompositeFilter extends AbstractLifeCycle implements Iterable<Filter>, Filter {
 
-    private final List<Filter> filters;
+    private static final Filter[] EMPTY_FILTERS = new Filter[0];
+    private final Filter[] filters;
 
     private CompositeFilter() {
-        this.filters = new ArrayList<>();
+        this.filters = EMPTY_FILTERS;
     }
 
-    private CompositeFilter(final List<Filter> filters) {
-        if (filters == null) {
-            this.filters = Collections.unmodifiableList(new ArrayList<Filter>());
-            return;
-        }
-        this.filters = Collections.unmodifiableList(filters);
+    private CompositeFilter(final Filter[] filters) {
+        this.filters = filters == null ? EMPTY_FILTERS : filters;
     }
 
     public CompositeFilter addFilter(final Filter filter) {
@@ -59,9 +55,9 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
             // null does nothing
             return this;
         }
-        final List<Filter> filterList = new ArrayList<>(this.filters);
-        filterList.add(filter);
-        return new CompositeFilter(Collections.unmodifiableList(filterList));
+        final Filter[] copy = Arrays.copyOf(this.filters, this.filters.length + 1);
+        copy[this.filters.length] = filter;
+        return new CompositeFilter(copy);
     }
 
     public CompositeFilter removeFilter(final Filter filter) {
@@ -69,17 +65,31 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
             // null does nothing
             return this;
         }
-        final List<Filter> filterList = new ArrayList<>(this.filters);
+        // This is not a great implementation but simpler than copying Apache Commons 
+        // Lang ArrayUtils.removeElement() and associated bits (MutableInt),
+        // which is OK since removing a filter should not be on the critical path.
+        final List<Filter> filterList = Arrays.asList(this.filters);
         filterList.remove(filter);
-        return new CompositeFilter(Collections.unmodifiableList(filterList));
+        return new CompositeFilter(filterList.toArray(new Filter[this.filters.length - 1]));
     }
 
     @Override
     public Iterator<Filter> iterator() {
-        return filters.iterator();
+        return new ObjectArrayIterator<>(filters);
     }
 
+    /**
+     * Gets a new list over the internal filter array.
+     * 
+     * @return a new list over the internal filter array
+     * @deprecated Use {@link #getFiltersArray()}
+     */
+    @Deprecated
     public List<Filter> getFilters() {
+        return Arrays.asList(filters);
+    }
+
+    public Filter[] getFiltersArray() {
         return filters;
     }
 
@@ -89,11 +99,11 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
      * @return whether this composite contains any filters.
      */
     public boolean isEmpty() {
-        return this.filters.isEmpty();
+        return this.filters.length == 0;
     }
 
     public int size() {
-        return filters.size();
+        return filters.length;
     }
 
     @Override
@@ -151,10 +161,10 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
      */
     @Override
     public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
-                         final Object... params) {
+            final Object... params) {
         Result result = Result.NEUTRAL;
-        for (final Filter filter : filters) {
-            result = filter.filter(logger, level, marker, msg, params);
+        for (int i = 0; i < filters.length; i++) {
+            result = filters[i].filter(logger, level, marker, msg, params);
             if (result == Result.ACCEPT || result == Result.DENY) {
                 return result;
             }
@@ -179,10 +189,10 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
      */
     @Override
     public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg,
-                         final Throwable t) {
+            final Throwable t) {
         Result result = Result.NEUTRAL;
-        for (final Filter filter : filters) {
-            result = filter.filter(logger, level, marker, msg, t);
+        for (int i = 0; i < filters.length; i++) {
+            result = filters[i].filter(logger, level, marker, msg, t);
             if (result == Result.ACCEPT || result == Result.DENY) {
                 return result;
             }
@@ -207,10 +217,10 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
      */
     @Override
     public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg,
-                         final Throwable t) {
+            final Throwable t) {
         Result result = Result.NEUTRAL;
-        for (final Filter filter : filters) {
-            result = filter.filter(logger, level, marker, msg, t);
+        for (int i = 0; i < filters.length; i++) {
+            result = filters[i].filter(logger, level, marker, msg, t);
             if (result == Result.ACCEPT || result == Result.DENY) {
                 return result;
             }
@@ -228,8 +238,8 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
     @Override
     public Result filter(final LogEvent event) {
         Result result = Result.NEUTRAL;
-        for (final Filter filter : filters) {
-            result = filter.filter(event);
+        for (int i = 0; i < filters.length; i++) {
+            result = filters[i].filter(event);
             if (result == Result.ACCEPT || result == Result.DENY) {
                 return result;
             }
@@ -240,13 +250,13 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder();
-        for (final Filter filter : filters) {
+        for (int i = 0; i < filters.length; i++) {
             if (sb.length() == 0) {
                 sb.append('{');
             } else {
                 sb.append(", ");
             }
-            sb.append(filter.toString());
+            sb.append(filters[i].toString());
         }
         if (sb.length() > 0) {
             sb.append('}');
@@ -263,9 +273,7 @@ public final class CompositeFilter extends AbstractLifeCycle implements Iterable
      */
     @PluginFactory
     public static CompositeFilter createFilters(@PluginElement("Filters") final Filter[] filters) {
-        final List<Filter> filterList = filters == null || filters.length == 0 ?
-            new ArrayList<Filter>() : Arrays.asList(filters);
-        return new CompositeFilter(filterList);
+        return new CompositeFilter(filters);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3761dba6/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
new file mode 100644
index 0000000..9f9897e
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An {@link java.util.Iterator Iterator} over an array of objects.
+ * <p>
+ * This iterator does not support {@link #remove}, as the object array cannot be
+ * structurally modified.
+ * <p>
+ * The iterator implements a {@link #reset} method, allowing the reset of the iterator
+ * back to the start if required.
+ *
+ * @param <E> the type to iterate over
+ * @since 3.0
+ * @version $Id: ObjectArrayIterator.java 1734648 2016-03-11 23:51:22Z ggregory $
+ */
+public class ObjectArrayIterator<E> implements /*Resettable*/ Iterator<E> {
+
+    /** The array */
+    final E[] array;
+    /** The start index to loop from */
+    final int startIndex;
+    /** The end index to loop to */
+    final int endIndex;
+    /** The current iterator index */
+    int index = 0;
+
+    //-------------------------------------------------------------------------
+    /**
+     * Constructs an ObjectArrayIterator that will iterate over the values in the
+     * specified array.
+     *
+     * @param array the array to iterate over
+     * @throws NullPointerException if <code>array</code> is <code>null</code>
+     */
+    public ObjectArrayIterator(final E... array) {
+        this(array, 0, array.length);
+    }
+
+    /**
+     * Constructs an ObjectArrayIterator that will iterate over the values in the
+     * specified array from a specific start index.
+     *
+     * @param array  the array to iterate over
+     * @param start  the index to start iterating at
+     * @throws NullPointerException if <code>array</code> is <code>null</code>
+     * @throws IndexOutOfBoundsException if the start index is out of bounds
+     */
+    public ObjectArrayIterator(final E array[], final int start) {
+        this(array, start, array.length);
+    }
+
+    /**
+     * Construct an ObjectArrayIterator that will iterate over a range of values
+     * in the specified array.
+     *
+     * @param array  the array to iterate over
+     * @param start  the index to start iterating at
+     * @param end  the index (exclusive) to finish iterating at
+     * @throws IndexOutOfBoundsException if the start or end index is out of bounds
+     * @throws IllegalArgumentException if end index is before the start
+     * @throws NullPointerException if <code>array</code> is <code>null</code>
+     */
+    public ObjectArrayIterator(final E array[], final int start, final int end) {
+        super();
+        if (start < 0) {
+            throw new ArrayIndexOutOfBoundsException("Start index must not be less than zero");
+        }
+        if (end > array.length) {
+            throw new ArrayIndexOutOfBoundsException("End index must not be greater than the array length");
+        }
+        if (start > array.length) {
+            throw new ArrayIndexOutOfBoundsException("Start index must not be greater than the array length");
+        }
+        if (end < start) {
+            throw new IllegalArgumentException("End index must not be less than start index");
+        }
+        this.array = array;
+        this.startIndex = start;
+        this.endIndex = end;
+        this.index = start;
+    }
+
+    // Iterator interface
+    //-------------------------------------------------------------------------
+
+    /**
+     * Returns true if there are more elements to return from the array.
+     *
+     * @return true if there is a next element to return
+     */
+    @Override
+    public boolean hasNext() {
+        return this.index < this.endIndex;
+    }
+
+    /**
+     * Returns the next element in the array.
+     *
+     * @return the next element in the array
+     * @throws NoSuchElementException if all the elements in the array
+     *    have already been returned
+     */
+    @Override
+    public E next() {
+        if (hasNext() == false) {
+            throw new NoSuchElementException();
+        }
+        return this.array[this.index++];
+    }
+
+    /**
+     * Throws {@link UnsupportedOperationException}.
+     *
+     * @throws UnsupportedOperationException always
+     */
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException("remove() method is not supported for an ObjectArrayIterator");
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+
+    /**
+     * Gets the array that this iterator is iterating over.
+     *
+     * @return the array this iterator iterates over
+     */
+    public E[] getArray() {
+        return this.array;
+    }
+
+    /**
+     * Gets the start index to loop from.
+     *
+     * @return the start index
+     */
+    public int getStartIndex() {
+        return this.startIndex;
+    }
+
+    /**
+     * Gets the end index to loop to.
+     *
+     * @return the end index
+     */
+    public int getEndIndex() {
+        return this.endIndex;
+    }
+
+    /**
+     * Resets the iterator back to the start index.
+     */
+    //@Override
+    public void reset() {
+        this.index = this.startIndex;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3761dba6/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
index bdb2522..440d5fb 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
@@ -59,10 +59,10 @@ public class CustomLevelsWithFiltersTest {
         assertNotNull(appender);
         final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
         assertNotNull(compFilter);
-        final List<Filter> filterList = compFilter.getFilters();
-        assertNotNull(filterList);
+        final Filter[] filters = compFilter.getFiltersArray();
+        assertNotNull(filters);
         boolean foundLevel = false;
-        for (final Filter filter : filterList) {
+        for (final Filter filter : filters) {
             final ThresholdFilter tFilter = (ThresholdFilter) filter;
             if (infom1Level.equals(tFilter.getLevel())) {
                 foundLevel = true;


[32/50] logging-log4j2 git commit: LOG4J2-1080 updated documentation after removing support for dropping events on partially full queue

Posted by rp...@apache.org.
LOG4J2-1080 updated documentation after removing support for dropping events on partially full queue


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: e91ea510a6b6689e7b7a84102312cde969aa0530
Parents: ba2ee52
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:58:20 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:58:20 2016 +1100

----------------------------------------------------------------------
 src/site/xdoc/manual/async.xml            |  8 ++++----
 src/site/xdoc/manual/configuration.xml.vm | 16 +++-------------
 2 files changed, 7 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e91ea510/src/site/xdoc/manual/async.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/async.xml b/src/site/xdoc/manual/async.xml
index 911c27a..36c7ebe 100644
--- a/src/site/xdoc/manual/async.xml
+++ b/src/site/xdoc/manual/async.xml
@@ -279,8 +279,8 @@
           There are also a few system properties that can be used to maintain application throughput even when
           the underlying appender cannot keep up with the logging rate and the queue is filling up.
           See the details for system properties
-          <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt>,
-            <tt>log4j2.DiscardThreshold</tt> and <tt>log4j2.DiscardQueueRatio</tt></a>.
+          <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt> and
+            <tt>log4j2.DiscardThreshold</tt></a>.
         </p>
       </subsection>
       <a name="MixedSync-Async" />
@@ -398,8 +398,8 @@
           There are also a few system properties that can be used to maintain application throughput even when
           the underlying appender cannot keep up with the logging rate and the queue is filling up.
           See the details for system properties
-          <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt>,
-            <tt>log4j2.DiscardThreshold</tt> and <tt>log4j2.DiscardQueueRatio</tt></a>.
+          <a href="configuration.html#AsyncEventRouter"><tt>log4j2.AsyncEventRouter</tt> and
+            <tt>log4j2.DiscardThreshold</tt></a>.
         </p>
       </subsection>
       <a name="Location" />

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e91ea510/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index 5e0a5fb..f1e72f0 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -1881,25 +1881,15 @@ public class AwesomeTest {
       <p>If no value is specified (the default) events are never discarded. If the queue is full, the
         logger call blocks until the event can be added to the queue.</p>
       <p>Specify <tt>Discard</tt> to drop events whose level is equal or less than the threshold level
-        (INFO by default) when the queue has been filled to the discard ratio (0.8 by default).</p>
-      <p>It is also possible to specify the fully qualified class name of a custom class that implements the
-        <tt>org.apache.logging.log4j.core.async.AsyncEventRouter</tt> interface.</p>
+        (INFO by default) when the queue is full.</p>
     </td>
   </tr>
   <tr>
     <td>log4j2.DiscardThreshold</td>
     <td>INFO</td>
     <td>Used by the DiscardingAsyncEventRouter to determine which events to drop when the queue
-      becomes too full. By default, <tt>INFO</tt>, <tt>DEBUG</tt> and <tt>TRACE</tt> level
-      events are discarded when the queue has been filled up to or beyond the discard ratio.
-      This property only has effect if <tt>Discard</tt> is specified as the
-      <tt>log4j2.AsyncEventRouter</tt>.</td>
-  </tr>
-  <tr>
-    <td>log4j2.DiscardQueueRatio</td>
-    <td>0.8</td>
-    <td>Used by the DiscardingAsyncEventRouter to determine when the queue is becoming too full.
-      By default, events may be discarded when the queue is 80% full or more.
+      becomes full. By default, <tt>INFO</tt>, <tt>DEBUG</tt> and <tt>TRACE</tt> level
+      events are discarded when the queue is full.
       This property only has effect if <tt>Discard</tt> is specified as the
       <tt>log4j2.AsyncEventRouter</tt>.</td>
   </tr>


[13/50] logging-log4j2 git commit: [LOG4J2-63] Support configuration from version 1.x log4j.properties. A start, with the ConsoleAppender.

Posted by rp...@apache.org.
[LOG4J2-63] Support configuration from version 1.x log4j.properties. A
start, with the ConsoleAppender.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 9371266e5f2afb2df8eee6721f372b0894f7c9c8
Parents: 2ccf95d
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 00:20:15 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 00:20:15 2016 -0800

----------------------------------------------------------------------
 .../config/Log4j1ConfigurationFactory.java      | 296 +++++++++++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  60 ++++
 .../log4j-console-PatternLayout.properties      |  19 ++
 .../log4j-console-SimpleLayout.properties       |  18 ++
 4 files changed, 393 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9371266e/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
new file mode 100644
index 0000000..470a3fe
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * Experimental ConfigurationFactory for Log4j 1.2 properties files.
+ * <p>
+ * Currently supports:
+ * </p>
+ * <ul>
+ * <li>log4j.debug</li>
+ * <li>log4j.rootLogger</li>
+ * <li>log4j.logger</li>
+ * <li>log4j.appender</li>
+ * <li>org.apache.log4j.ConsoleAppender</li>
+ * <li>org.apache.log4j.PatternLayout</li>
+ * <ul>
+ * <li>Follow</li>
+ * <li>Target</li>
+ * <li>layout = org.apache.log4j.PatternLayout</li>
+ * <li>layout = org.apache.log4j.SimpleLayout</li>
+ * <li>layout.ConversionPattern</li>
+ * </ul>
+ * </ul>
+ */
+// TODO
+// @Plugin(name = "Log4j1ConfigurationFactory", category = ConfigurationFactory.CATEGORY)
+//
+// Best Value?
+// @Order(50)
+public class Log4j1ConfigurationFactory extends ConfigurationFactory {
+
+    private Map<String, String> buildClassToPropertyPrefixMap(final Properties properties,
+            final String[] sortedAppenderNames) {
+        final String prefix = "log4j.appender.";
+        final int preLength = prefix.length();
+        final Map<String, String> map = new HashMap<>(sortedAppenderNames.length);
+        for (final Entry<Object, Object> entry : properties.entrySet()) {
+            final Object keyObj = entry.getKey();
+            if (keyObj != null) {
+                final String key = keyObj.toString();
+                if (key.startsWith(prefix)) {
+                    if (key.indexOf('.', preLength) < 0) {
+                        final String name = key.substring(preLength);
+                        if (Arrays.binarySearch(sortedAppenderNames, name) >= 0) {
+                            final Object value = entry.getValue();
+                            if (value != null) {
+                                map.put(name, value.toString());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return map;
+    }
+
+    private void buildConsoleAppender(final Properties properties, final String name,
+            final ConfigurationBuilder<BuiltConfiguration> builder) {
+        final AppenderComponentBuilder appenderBuilder = builder.newAppender(name, "CONSOLE");
+        buildConsoleAppenderTarget(properties, name, builder, appenderBuilder);
+        buildConsoleAppenderLayout(properties, name, builder, appenderBuilder);
+        buildConsoleAppenderFollow(properties, name, builder, appenderBuilder);
+        builder.add(appenderBuilder);
+    }
+
+    private void buildConsoleAppenderLayout(final Properties properties, final String name,
+            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
+        final String layoutValue = getLog4jAppenderValue(properties, name, "layout", null);
+        if (layoutValue != null) {
+            final String cpValue = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
+            switch (layoutValue) {
+            case "org.apache.log4j.PatternLayout": {
+                final LayoutComponentBuilder layoutBuilder = newPatternLayout(builder, cpValue);
+                appenderBuilder.add(layoutBuilder);
+                break;
+            }
+            case "org.apache.log4j.SimpleLayout": {
+                final LayoutComponentBuilder layoutBuilder = newPatternLayout(builder, "%level - %m%n");
+                appenderBuilder.add(layoutBuilder);
+                break;
+            }
+            default:
+                reportWarning("Unsupported value for console appender layout: " + layoutValue);
+            }
+        }
+    }
+
+    private LayoutComponentBuilder newPatternLayout(final ConfigurationBuilder<BuiltConfiguration> builder,
+            final String pattern) {
+        final LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout");
+        if (pattern != null) {
+            layoutBuilder.addAttribute("pattern", pattern);
+        }
+        return layoutBuilder;
+    }
+
+    private void buildConsoleAppenderTarget(final Properties properties, final String name,
+            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
+        final String value = getLog4jAppenderValue(properties, name, "Target", "System.out");
+        if (value != null) {
+            final Target target;
+            switch (value) {
+            case "System.out":
+                target = ConsoleAppender.Target.SYSTEM_OUT;
+                break;
+            case "System.err":
+                target = ConsoleAppender.Target.SYSTEM_ERR;
+                break;
+            default:
+                reportWarning("Unknow value for console Target: " + value);
+                target = null;
+            }
+            if (target != null) {
+                appenderBuilder.addAttribute("target", target);
+            }
+        }
+    }
+
+    private void buildConsoleAppenderFollow(final Properties properties, final String name,
+            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
+        final String value = getLog4jAppenderValue(properties, name, "Follow", "false");
+        if (value != null) {
+            appenderBuilder.addAttribute("follow", Boolean.valueOf(value).booleanValue());
+        }
+    }
+
+    Configuration createConfiguration(final String configName, final URI configLocation,
+            final ConfigurationBuilder<BuiltConfiguration> builder) throws IOException {
+        builder.setConfigurationName(configName);
+        final Properties properties = load(configLocation);
+        if (properties == null) {
+            return null;
+        }
+        // DEBUG
+        final String debugValue = getLog4jValue(properties, "debug");
+        if (Boolean.valueOf(debugValue)) {
+            builder.setStatusLevel(Level.DEBUG);
+        }
+        // Root
+        final String[] sortedAppenderNamesC = buildRootLogger(builder, getRootCategoryValue(properties));
+        final String[] sortedAppenderNamesL = buildRootLogger(builder, getRootLoggerValue(properties));
+        final String[] sortedAppenderNames = sortedAppenderNamesL.length > 0 ? sortedAppenderNamesL
+                : sortedAppenderNamesC;
+        // Appenders
+        final Map<String, String> classNameToProperty = buildClassToPropertyPrefixMap(properties, sortedAppenderNames);
+        for (final Entry<String, String> entry : classNameToProperty.entrySet()) {
+            final String appenderName = entry.getKey();
+            switch (entry.getValue()) {
+            case "org.apache.log4j.ConsoleAppender":
+                buildConsoleAppender(properties, appenderName, builder);
+                break;
+            default:
+                reportWarning("Ignoring appender " + appenderName
+                        + "; consider porting your configuration file to the current Log4j format.");
+            }
+        }
+        // Loggers
+        buildLoggers(properties, "log4j.category.", builder);
+        buildLoggers(properties, "log4j.logger.", builder);
+        return builder.build();
+    }
+
+    private String[] buildRootLogger(final ConfigurationBuilder<BuiltConfiguration> builder,
+            final String rootLoggerValue) {
+        if (rootLoggerValue == null) {
+            return new String[0];
+        }
+        final String[] rootLoggerParts = rootLoggerValue.split("\\s*,\\s*");
+        final Level rootLoggerLevel = rootLoggerParts.length > 0 ? Level.valueOf(rootLoggerParts[0]) : Level.ERROR;
+        builder.add(builder.newRootLogger(rootLoggerLevel));
+        final String[] sortedAppenderNames = Arrays.copyOfRange(rootLoggerParts, 1, rootLoggerParts.length);
+        Arrays.sort(sortedAppenderNames);
+        return sortedAppenderNames;
+    }
+
+    private void buildLoggers(final Properties properties, final String prefix,
+            final ConfigurationBuilder<BuiltConfiguration> builder) {
+        final int preLength = prefix.length();
+        for (final Entry<Object, Object> entry : properties.entrySet()) {
+            final Object keyObj = entry.getKey();
+            if (keyObj != null) {
+                final String key = keyObj.toString();
+                if (key.startsWith(prefix)) {
+                    final String name = key.substring(preLength);
+                    final Object value = entry.getValue();
+                    if (value != null) {
+                        builder.add(builder.newLogger(name, Level.valueOf(value.toString())));
+                    }
+                }
+            }
+        }
+
+    }
+
+    @Override
+    public Configuration getConfiguration(final ConfigurationSource source) {
+        return getConfiguration(source.toString(), null);
+    }
+
+    @Override
+    public Configuration getConfiguration(final String name, final URI configLocation) {
+        try {
+            return createConfiguration(name, configLocation, newConfigurationBuilder());
+        } catch (final IOException e) {
+            StatusLogger.getLogger().error(e);
+            return null;
+        }
+    }
+
+    private String getLog4jAppenderValue(final Properties properties, final String appenderName,
+            final String attributeName, final String defaultValue) {
+        return properties.getProperty("log4j.appender." + appenderName + "." + attributeName, defaultValue);
+    }
+
+    private String getLog4jValue(final Properties properties, final String key) {
+        return properties.getProperty("log4j." + key);
+    }
+
+    private String getRootCategoryValue(final Properties properties) {
+        return getLog4jValue(properties, "rootCategory");
+    }
+
+    private String getRootLoggerValue(final Properties properties) {
+        return getLog4jValue(properties, "rootLogger");
+    }
+
+    @Override
+    protected String[] getSupportedTypes() {
+        return new String[] { "*.properties", ".xml" };
+    }
+
+    private Properties load(final URI uri) throws IOException {
+        final Properties properties = toProperties(uri);
+        final String rootCategoryValue = getRootCategoryValue(properties);
+        final String rootLoggerValue = getRootLoggerValue(properties);
+        if (rootCategoryValue == null && rootLoggerValue == null) {
+            // This is not a Log4j 1 properties file.
+            return null;
+        }
+        return properties;
+    }
+
+    private void reportWarning(final String msg) {
+        StatusLogger.getLogger().warn("Log4j version 1 to 2 configuration bridge: " + msg);
+
+    }
+
+    private Properties toProperties(final URI uri) throws IOException {
+        final Properties properties;
+        try (InputStream in = uri.toURL().openStream()) {
+            properties = new Properties();
+            if (uri.toString().endsWith(".xml")) {
+                properties.loadFromXML(in);
+            } else {
+                properties.load(in);
+            }
+        }
+        return properties;
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9371266e/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
new file mode 100644
index 0000000..13bcdc2
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j.config;
+
+import java.net.URL;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Log4j1ConfigurationFactoryTest {
+
+    private void testConsole(final String configResource, final String expectedPattern) throws Exception {
+        final URL configLocation = ClassLoader.getSystemResource(configResource);
+        Assert.assertNotNull(configLocation);
+        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration("test",
+                configLocation.toURI());
+        Assert.assertNotNull(configuration);
+        final ConsoleAppender appender = configuration.getAppender("Console");
+        Assert.assertNotNull(appender);
+        // Can't set ImmediateFlush for a Console Appender in Log4j 2 like you can in 1.2
+        Assert.assertTrue(appender.getImmediateFlush());        
+        Assert.assertEquals(Target.SYSTEM_ERR, appender.getTarget());
+        final PatternLayout layout = (PatternLayout) appender.getLayout();
+        Assert.assertEquals(expectedPattern, layout.getConversionPattern());
+        //
+        final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
+        Assert.assertNotNull(loggerConfig);
+        Assert.assertEquals(Level.DEBUG, loggerConfig.getLevel());
+    }
+
+    @Test
+    public void testConsolePatternLayout() throws Exception {
+        testConsole("config-1.2/log4j-console-PatternLayout.properties", "%d{ISO8601} [%t][%c] %-5p: %m%n");
+    }
+
+    @Test
+    public void testConsoleSimpleLayout() throws Exception {
+        testConsole("config-1.2/log4j-console-SimpleLayout.properties", "%level - %m%n");
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9371266e/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
new file mode 100644
index 0000000..fab7070
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
@@ -0,0 +1,19 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p: %m%n
+
+log4j.logger.com.example.foo = DEBUG

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9371266e/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
new file mode 100644
index 0000000..5e915f8
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
@@ -0,0 +1,18 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.SimpleLayout
+
+log4j.logger.com.example.foo = DEBUG


[38/50] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 3be541cd7ed4d96ab53728ec369bba7b526b869d
Parents: a8bbdcd 2c70b44
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:26:51 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:26:51 2016 +1100

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/util/ObjectArrayIterator.java     | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------



[50/50] logging-log4j2 git commit: LOG4J2-1278 added methods with unrolled varargs to ReusableMessageFactory

Posted by rp...@apache.org.
LOG4J2-1278 added methods with unrolled varargs to ReusableMessageFactory


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: b6ef29324c5d446cbc4c24063ca85048ef48d0ed
Parents: 7b9077c
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 16 17:09:23 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 16 17:09:23 2016 +1100

----------------------------------------------------------------------
 .../log4j/message/ReusableMessageFactory.java   | 59 +++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b6ef2932/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessageFactory.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessageFactory.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessageFactory.java
index 85f2dea..706e31d 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessageFactory.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableMessageFactory.java
@@ -30,7 +30,7 @@ import org.apache.logging.log4j.util.PerformanceSensitive;
  * @since 2.6
  */
 @PerformanceSensitive("allocation")
-public final class ReusableMessageFactory implements MessageFactory, Serializable {
+public final class ReusableMessageFactory implements MessageFactory2, Serializable {
 
     /**
      * Instance of ReusableMessageFactory..
@@ -90,6 +90,63 @@ public final class ReusableMessageFactory implements MessageFactory, Serializabl
         return getParameterized().set(message, params);
     }
 
+    @Override
+    public Message newMessage(final String message, final Object p0) {
+        return getParameterized().set(message, p0);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1) {
+        return getParameterized().set(message, p0, p1);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2) {
+        return getParameterized().set(message, p0, p1, p2);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2,
+            final Object p3) {
+        return getParameterized().set(message, p0, p1, p2, p3);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4, final Object p5) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4, p5);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4, final Object p5, final Object p6) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4, p5, p6);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4, final Object p5, final Object p6, final Object p7) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4, p5, p6, p7);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4, final Object p5, final Object p6, final Object p7, final Object p8) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4, p5, p6, p7, p8);
+    }
+
+    @Override
+    public Message newMessage(final String message, final Object p0, final Object p1, final Object p2, final Object p3,
+            final Object p4, final Object p5, final Object p6, final Object p7, final Object p8, final Object p9) {
+        return getParameterized().set(message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
+    }
+
     /**
      * Creates {@link ReusableSimpleMessage} instances.
      *


[31/50] logging-log4j2 git commit: LOG4J2-1080 updated tests after removing support for dropping events on partially full queue

Posted by rp...@apache.org.
LOG4J2-1080 updated tests after removing support for dropping events on partially full queue


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: ba2ee521bc0456fed21d420e63b17e2b8d1b8081
Parents: d1d9ac3
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:58:00 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:58:00 2016 +1100

----------------------------------------------------------------------
 .../core/async/AsyncEventRouterFactoryTest.java | 57 +++-----------
 .../core/async/DefaultAsyncEventRouterTest.java | 25 +------
 .../async/DiscardingAsyncEventRouterTest.java   | 79 +++++++-------------
 3 files changed, 38 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
index 804401b..cad81b7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactoryTest.java
@@ -40,13 +40,12 @@ public class AsyncEventRouterFactoryTest {
 
     private void clearProperties() {
         System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER);
-        System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO);
         System.clearProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL);
     }
 
     @Test
     public void testCreateReturnsDefaultRouterByDefault() throws Exception {
-        AsyncEventRouter router = AsyncEventRouterFactory.create(256);
+        AsyncEventRouter router = AsyncEventRouterFactory.create();
         assertEquals(DefaultAsyncEventRouter.class, router.getClass());
     }
 
@@ -54,34 +53,26 @@ public class AsyncEventRouterFactoryTest {
     public void testCreateReturnsDiscardingRouterIfSpecified() throws Exception {
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
-        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass());
 
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 DiscardingAsyncEventRouter.class.getSimpleName());
-        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass());
 
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 DiscardingAsyncEventRouter.class.getName());
-        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+        assertEquals(DiscardingAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass());
     }
 
     @Test
     public void testCreateDiscardingRouterDefaultThresholdLevelInfo() throws Exception {
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
-        assertEquals(Level.INFO, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+        assertEquals(Level.INFO, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create()).
                 getThresholdLevel());
     }
 
     @Test
-    public void testCreateDiscardingRouterDefaultThresholdQueueRemainingCapacity() throws Exception {
-        System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
-                AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
-        assertEquals((int) (256 * (1.0 - 0.8)), ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
-                getThresholdQueueRemainingCapacity());
-    }
-
-    @Test
     public void testCreateDiscardingRouterThresholdLevelCustomizable() throws Exception {
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
@@ -89,43 +80,17 @@ public class AsyncEventRouterFactoryTest {
         for (Level level : Level.values()) {
             System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL,
                     level.name());
-            assertEquals(level, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
+            assertEquals(level, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create()).
                     getThresholdLevel());
         }
     }
 
-    @Test
-    public void testCreateDiscardingRouterThresholdQueueCapacityCustomizable() throws Exception {
-        System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
-                AsyncEventRouterFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
-        float[] ratios = new float[] {0.1f, 0.2f, 0.5f, 0.8f, 0.9f};
-        for (final float ratio : ratios) {
-            System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_DISCARDING_QUEUE_RATIO,
-                    String.valueOf(ratio));
-            int expected = (int) (256 * (1.0 - ratio));
-            assertEquals(expected, ((DiscardingAsyncEventRouter) AsyncEventRouterFactory.create(256)).
-                    getThresholdQueueRemainingCapacity());
-        }
-    }
-
     static class CustomRouterDefaultConstructor implements AsyncEventRouter {
         public CustomRouterDefaultConstructor() {
         }
 
         @Override
-        public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
-                final int queueRemainingCapacity) {
-            return null;
-        }
-    }
-
-    static class CustomRouterIntConstructor implements AsyncEventRouter {
-        public CustomRouterIntConstructor(int queueSize) {
-        }
-
-        @Override
-        public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
-                final int queueRemainingCapacity) {
+        public EventRoute getRoute(final long backgroundThreadId, final Level level) {
             return null;
         }
     }
@@ -137,17 +102,13 @@ public class AsyncEventRouterFactoryTest {
     public void testCreateReturnsCustomRouterIfSpecified() throws Exception {
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 CustomRouterDefaultConstructor.class.getName());
-        assertEquals(CustomRouterDefaultConstructor.class, AsyncEventRouterFactory.create(256).getClass());
-
-        System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
-                CustomRouterIntConstructor.class.getName());
-        assertEquals(CustomRouterIntConstructor.class, AsyncEventRouterFactory.create(256).getClass());
+        assertEquals(CustomRouterDefaultConstructor.class, AsyncEventRouterFactory.create().getClass());
     }
 
     @Test
     public void testCreateReturnsDefaultRouterIfSpecifiedCustomRouterFails() throws Exception {
         System.setProperty(AsyncEventRouterFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
                 DoesNotImplementInterface.class.getName());
-        assertEquals(DefaultAsyncEventRouter.class, AsyncEventRouterFactory.create(256).getClass());
+        assertEquals(DefaultAsyncEventRouter.class, AsyncEventRouterFactory.create().getClass());
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
index dcec225..aa6fcbf 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouterTest.java
@@ -35,33 +35,16 @@ public class DefaultAsyncEventRouterTest {
     }
 
     @Test
-    public void testGetRouteEnqueuesIfQueueNotFull() throws Exception {
-        DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 1));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 1));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 1));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 1));
-    }
-
-    @Test
     public void testGetRouteEnqueuesIfQueueFullAndCalledFromDifferentThread() throws Exception {
         DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 512, 0));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 512, 0));
+        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL));
+        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF));
     }
 
     @Test
     public void testGetRouteSynchronousIfQueueFullAndCalledFromSameThread() throws Exception {
         DefaultAsyncEventRouter router = new DefaultAsyncEventRouter();
-        assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL, 512, 0));
-        assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF, 512, 0));
+        assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.ALL));
+        assertEquals(EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), Level.OFF));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba2ee521/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
index 1e9b66a..85667c1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouterTest.java
@@ -36,111 +36,82 @@ public class DiscardingAsyncEventRouterTest {
 
     @Test(expected = NullPointerException.class)
     public void testConstructorDisallowsNullThresholdLevel() {
-        new DiscardingAsyncEventRouter(128, 0.5F, null);
+        new DiscardingAsyncEventRouter(null);
     }
 
     @Test
     public void testThresholdLevelIsConstructorValue() {
-        assertSame(Level.ALL, new DiscardingAsyncEventRouter(128, 0.5F, Level.ALL).getThresholdLevel());
-        assertSame(Level.OFF, new DiscardingAsyncEventRouter(128, 0.5F, Level.OFF).getThresholdLevel());
-        assertSame(Level.INFO, new DiscardingAsyncEventRouter(128, 0.5F, Level.INFO).getThresholdLevel());
-    }
-
-    @Test
-    public void testThresholdRemainingCapacityBasedOnConstructorValues() {
-        // discard when queue full
-        assertEquals(0, new DiscardingAsyncEventRouter(4, 1F, Level.ALL).getThresholdQueueRemainingCapacity());
-
-        // discard when queue half full
-        assertEquals(2, new DiscardingAsyncEventRouter(4, 0.5F, Level.ALL).getThresholdQueueRemainingCapacity());
-
-        // discard even if queue empty
-        assertEquals(4, new DiscardingAsyncEventRouter(4, 0F, Level.ALL).getThresholdQueueRemainingCapacity());
-    }
-
-    @Test
-    public void testGetRouteEnqueuesIfThresholdCapacityNotReached() throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 256));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.ALL, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.ALL, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.OFF, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.OFF, 256, 255));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.FATAL, 256, 129));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.FATAL, 256, 129));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(currentThreadId(), Level.TRACE, 256, 129));
-        assertEquals(EventRoute.ENQUEUE, router.getRoute(otherThreadId(), Level.TRACE, 256, 129));
+        assertSame(Level.ALL, new DiscardingAsyncEventRouter(Level.ALL).getThresholdLevel());
+        assertSame(Level.OFF, new DiscardingAsyncEventRouter(Level.OFF).getThresholdLevel());
+        assertSame(Level.INFO, new DiscardingAsyncEventRouter(Level.INFO).getThresholdLevel());
     }
 
     @Test
     public void testGetRouteDiscardsIfThresholdCapacityReachedAndLevelEqualOrLessSpecificThanThreshold()
             throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN);
 
         for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) {
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 1));
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 1));
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 128));
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 128));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level));
         }
     }
 
     @Test
     public void testGetRouteDiscardsIfQueueFullAndLevelEqualOrLessSpecificThanThreshold() throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN);
 
         for (Level level : new Level[] {Level.WARN, Level.INFO, Level.DEBUG, Level.TRACE, Level.ALL}) {
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level, 256, 0));
-            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level, 256, 0));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(currentThreadId(), level));
+            assertEquals(level.name(), EventRoute.DISCARD, router.getRoute(otherThreadId(), level));
         }
     }
 
     @Test
     public void testGetRouteEnqueuesIfThresholdCapacityReachedButLevelMoreSpecificThanThreshold()
             throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN);
 
         for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
-            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 1));
-            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 1));
-            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(currentThreadId(), level, 256, 128));
-            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 128));
+            assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level));
+            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level));
+            assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level));
+            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level));
         }
     }
 
     @Test
     public void testGetRouteEnqueuesIfOtherThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN);
 
         for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
-            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level, 256, 0));
+            assertEquals(level.name(), EventRoute.ENQUEUE, router.getRoute(otherThreadId(), level));
         }
     }
 
     @Test
     public void testGetRouteSynchronousIfCurrentThreadQueueFullAndLevelMoreSpecificThanThreshold() throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(256, 0.5F, Level.WARN);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.WARN);
 
         for (Level level : new Level[] {Level.ERROR, Level.FATAL, Level.OFF}) {
-            assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level, 256, 0));
+            assertEquals(level.name(), EventRoute.SYNCHRONOUS, router.getRoute(currentThreadId(), level));
         }
     }
 
     @Test
     public void testGetDiscardCount() throws Exception {
-        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(4, 0F, Level.INFO);
+        DiscardingAsyncEventRouter router = new DiscardingAsyncEventRouter(Level.INFO);
         assertEquals("initially", 0, DiscardingAsyncEventRouter.getDiscardCount(router));
 
-        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
         assertEquals("increase", 1, DiscardingAsyncEventRouter.getDiscardCount(router));
 
-        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
         assertEquals("increase", 2, DiscardingAsyncEventRouter.getDiscardCount(router));
 
-        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO, 256, 0));
+        assertEquals(EventRoute.DISCARD, router.getRoute(-1L, Level.INFO));
         assertEquals("increase", 3, DiscardingAsyncEventRouter.getDiscardCount(router));
     }
 }
\ No newline at end of file


[04/50] logging-log4j2 git commit: LOG4J2-1310 - JndiLookup mindlessly casts to String and should use String.valueOf().

Posted by rp...@apache.org.
LOG4J2-1310 - JndiLookup mindlessly casts to String and should use String.valueOf().


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: c6318b63818427833db2dc08389c463102c1a66e
Parents: ed6c608
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 11:24:17 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 11:24:17 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/lookup/JndiLookup.java     |  2 +-
 .../logging/log4j/core/lookup/JndiLookupTest.java | 18 ++++++++++++++++++
 src/changes/changes.xml                           |  3 +++
 3 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
index d7d50cb..1cd4290 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
@@ -52,7 +52,7 @@ public class JndiLookup extends AbstractLookup {
         final String jndiName = convertJndiName(key);
         final JndiManager jndiManager = JndiManager.getDefaultManager();
         try {
-            return jndiManager.lookup(jndiName);
+            return String.valueOf(jndiManager.lookup(jndiName));
         } catch (final NamingException e) {
             LOGGER.warn(LOOKUP, "Error looking up JNDI resource [{}].", jndiName, e);
             return null;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
index 97f6a3b..1211cf5 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
+import java.util.Arrays;
+import java.util.Collection;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -34,6 +36,10 @@ public class JndiLookupTest {
 
     private static final String TEST_CONTEXT_RESOURCE_NAME = "logging/context-name";
     private static final String TEST_CONTEXT_NAME = "app-1";
+    private static final String TEST_INTEGRAL_NAME = "int-value";
+    private static final int TEST_INTEGRAL_VALUE = 42;
+    private static final String TEST_STRINGS_NAME = "string-collection";
+    private static final Collection<String> TEST_STRINGS_COLLECTION = Arrays.asList("one", "two", "three");
 
     private Context context;
 
@@ -42,6 +48,8 @@ public class JndiLookupTest {
         MockContextFactory.setAsInitial();
         context = new InitialContext();
         context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_CONTEXT_RESOURCE_NAME, TEST_CONTEXT_NAME);
+        context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_INTEGRAL_NAME, TEST_INTEGRAL_VALUE);
+        context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_STRINGS_NAME, TEST_STRINGS_COLLECTION);
     }
 
     @After
@@ -66,4 +74,14 @@ public class JndiLookupTest {
         final String nonExistingResource = lookup.lookup("logging/non-existing-resource");
         assertNull(nonExistingResource);
     }
+
+    @Test
+    public void testNonStringLookup() throws Exception {
+        // LOG4J2-1310
+        final StrLookup lookup = new JndiLookup();
+        final String integralValue = lookup.lookup(TEST_INTEGRAL_NAME);
+        assertEquals(String.valueOf(TEST_INTEGRAL_VALUE), integralValue);
+        final String collectionValue = lookup.lookup(TEST_STRINGS_NAME);
+        assertEquals(String.valueOf(TEST_STRINGS_COLLECTION), collectionValue);
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 61006a1..1313ac9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -205,6 +205,9 @@
       <action issue="LOG4J2-1133" dev="mattsicker" type="add">
         Add JNDI lookup documentation.
       </action>
+      <action issue="LOG4J2-1310" dev="mattsicker" type="fix">
+        JndiLookup mindlessly casts to String and should use String.valueOf().
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">


[47/50] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by rp...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: ba5cf45628fe48a915821aad92b58a5f3b322fc2
Parents: 8e13c98 52d04e0
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 15 02:08:30 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 15 02:08:30 2016 -0700

----------------------------------------------------------------------
 log4j-core/pom.xml                              |   6 +
 .../logging/log4j/core/GcFreeLoggingTest.java   | 131 +++++++++++++++++++
 pom.xml                                         |   6 +
 3 files changed, 143 insertions(+)
----------------------------------------------------------------------



[34/50] logging-log4j2 git commit: LOG4J2-1080 AsyncLoggerConfig now always tries to enqueue log events; if this fails because the queue is full, then fall back to asking AsyncEventRouter what to do with the event

Posted by rp...@apache.org.
LOG4J2-1080 AsyncLoggerConfig now always tries to enqueue log events; if this fails because the queue is full, then fall back to asking AsyncEventRouter what to do with the event


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 7a7f5e4ed1ce8a27357a12a06d32ca2b04e5eb56
Parents: 76067f2
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:01:34 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:01:34 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLoggerConfig.java       |  6 ++++--
 .../log4j/core/async/AsyncLoggerConfigDelegate.java       |  2 ++
 .../log4j/core/async/AsyncLoggerConfigDisruptor.java      | 10 ++++++++--
 3 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/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 24d0086..f1c6800 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
@@ -88,8 +88,10 @@ public class AsyncLoggerConfig extends LoggerConfig {
     protected void callAppenders(final LogEvent event) {
         populateLazilyInitializedFields(event);
 
-        final EventRoute eventRoute = delegate.getEventRoute(event.getLevel());
-        eventRoute.logMessage(this, event);
+        if (!delegate.tryEnqueue(event, this)) {
+            final EventRoute eventRoute = delegate.getEventRoute(event.getLevel());
+            eventRoute.logMessage(this, event);
+        }
     }
 
     private void populateLazilyInitializedFields(final LogEvent event) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
index e49a004..5cbe0e4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
@@ -46,4 +46,6 @@ public interface AsyncLoggerConfigDelegate {
     EventRoute getEventRoute(final Level level);
 
     void enqueueEvent(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
+
+    boolean tryEnqueue(LogEvent event, AsyncLoggerConfig asyncLoggerConfig);
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a7f5e4e/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index 20e025c..20abda8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -162,7 +162,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy");
         executor = Executors.newSingleThreadExecutor(THREAD_FACTORY);
         backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor);
-        asyncEventRouter = AsyncEventRouterFactory.create(ringBufferSize);
+        asyncEventRouter = AsyncEventRouterFactory.create();
 
         disruptor = new Disruptor<>(FACTORY, ringBufferSize, executor, ProducerType.MULTI, waitStrategy);
 
@@ -229,7 +229,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         if (remainingCapacity < 0) {
             return EventRoute.DISCARD;
         }
-        return asyncEventRouter.getRoute(backgroundThreadId, logLevel, ringBufferSize, remainingCapacity);
+        return asyncEventRouter.getRoute(backgroundThreadId, logLevel);
     }
 
     private int remainingDisruptorCapacity() {
@@ -278,6 +278,12 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         disruptor.getRingBuffer().publishEvent(TRANSLATOR, logEvent, asyncLoggerConfig);
     }
 
+    @Override
+    public boolean tryEnqueue(final LogEvent event, final AsyncLoggerConfig asyncLoggerConfig) {
+        final LogEvent logEvent = prepareEvent(event);
+        return disruptor.getRingBuffer().tryPublishEvent(TRANSLATOR, logEvent, asyncLoggerConfig);
+    }
+
     private LogEvent ensureImmutable(final LogEvent event) {
         LogEvent result = event;
         if (event instanceof RingBufferLogEvent) {


[06/50] logging-log4j2 git commit: LOG4J2-248 - Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader

Posted by rp...@apache.org.
LOG4J2-248 - Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 04a9ce6792a4d867b766aa4e251495310c6debf5
Parents: 2ccf95d
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 14:39:44 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 14:39:44 2016 -0600

----------------------------------------------------------------------
 .../org/apache/logging/log4j/web/Log4jWebInitializerImpl.java   | 5 +++--
 src/changes/changes.xml                                         | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/04a9ce67/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
index 2da549c..3fcc7d9 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
@@ -41,6 +41,7 @@ import org.apache.logging.log4j.core.util.Loader;
 import org.apache.logging.log4j.core.util.NetUtils;
 import org.apache.logging.log4j.core.util.SetUtils;
 import org.apache.logging.log4j.spi.LoggerContextFactory;
+import org.apache.logging.log4j.util.LoaderUtil;
 
 /**
  * This class initializes and deinitializes Log4j no matter how the initialization occurs.
@@ -265,8 +266,8 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
             // we compile against 3.0 to support Log4jServletContainerInitializer, but we don't require 3.0
             return this.servletContext.getClassLoader();
         } catch (final Throwable ignore) {
-            // otherwise, use this class's class loader
-            return Log4jWebInitializerImpl.class.getClassLoader();
+            // LOG4J2-248: use TCCL if possible
+            return LoaderUtil.getThreadContextClassLoader();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/04a9ce67/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1895b0f..68e3ec8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -211,6 +211,9 @@
       <action issue="LOG4J2-1206" dev="mattsicker" type="update">
         org.apache.logging.log4j.core.LoggerContext#updateLoggers should call firePropertyChangeEvent.
       </action>
+      <action issue="LOG4J2-248" dev="mattsicker" type="fix">
+        Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader.
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">


[25/50] logging-log4j2 git commit: Oops, forgot to remove import.

Posted by rp...@apache.org.
Oops, forgot to remove import.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 5bd76ac1e3aced984826ae76e696df1b1ce7ad11
Parents: 3761dba
Author: ggregory <gg...@apache.org>
Authored: Fri Mar 11 17:05:57 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Fri Mar 11 17:05:57 2016 -0800

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5bd76ac1/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
index 440d5fb..1808492 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CustomLevelsWithFiltersTest.java
@@ -19,8 +19,6 @@ package org.apache.logging.log4j.core;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.List;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.config.Configuration;


[16/50] logging-log4j2 git commit: [LOG4J2-63] Support configuration from version 1.x log4j.properties. Partial support for TTCC layout (defaults only).

Posted by rp...@apache.org.
[LOG4J2-63] Support configuration from version 1.x log4j.properties.
Partial support for TTCC layout (defaults only).

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: d6c916bbc4f417dc67982724f90a62d660dcc169
Parents: 1ecb8ec
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 00:48:48 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 00:48:48 2016 -0800

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationFactory.java  |  6 ++++++
 .../config/Log4j1ConfigurationFactoryTest.java    |  6 ++++++
 .../log4j-console-TTCCLayout.properties           | 18 ++++++++++++++++++
 3 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6c916bb/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 0e5d8d6..4dcad77 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -54,6 +54,7 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <li>Target</li>
  * <li>layout = org.apache.log4j.PatternLayout</li>
  * <li>layout = org.apache.log4j.SimpleLayout</li>
+ * <li>layout = org.apache.log4j.TTCCLayout (partial)</li>
  * <li>layout = org.apache.log4j.HtmlLayout (partial)</li>
  * <li>layout = org.apache.log4j.XmlLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
@@ -115,6 +116,11 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 appenderBuilder.add(newPatternLayout(builder, "%level - %m%n"));
                 break;
             }
+            case "org.apache.log4j.TTCCLayout": {
+                // TODO We do not have a %d for the time since the start of the app?
+                appenderBuilder.add(newPatternLayout(builder, "%d{UNIX_MILLIS} [%threadName] %level %logger - %m%n"));
+                break;
+            }
             case "org.apache.log4j.HTMLLayout": {
                 appenderBuilder.add(builder.newLayout("HtmlLayout"));
                 break;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6c916bb/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index c31fe37..013bb74 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -69,6 +69,12 @@ public class Log4j1ConfigurationFactoryTest {
     }
 
     @Test
+    public void testConsoleTtccLayout() throws Exception {
+        final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-TTCCLayout.properties");
+        Assert.assertEquals("%d{UNIX_MILLIS} [%threadName] %level %logger - %m%n", layout.getConversionPattern());
+    }
+
+    @Test
     public void testConsoleXmlLayout() throws Exception {
         final Layout<?> layout = testConsole("config-1.2/log4j-console-XmlLayout.properties");
         Assert.assertTrue(layout instanceof XmlLayout);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d6c916bb/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
new file mode 100644
index 0000000..d6bd829
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
@@ -0,0 +1,18 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.TTCCLayout
+
+log4j.logger.com.example.foo = DEBUG


[05/50] logging-log4j2 git commit: LOG4J2-1206 - org.apache.logging.log4j.core.LoggerContext#updateLoggers should call firePropertyChangeEvent

Posted by rp...@apache.org.
LOG4J2-1206 - org.apache.logging.log4j.core.LoggerContext#updateLoggers should call firePropertyChangeEvent


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 2ccf95d7c4696f19e23749188bb16578456a4be8
Parents: c6318b6
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 11:37:32 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 11:37:32 2016 -0600

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/LoggerContext.java |  2 ++
 .../apache/logging/log4j/core/LoggerUpdateTest.java  | 15 +++++++++++++++
 src/changes/changes.xml                              |  3 +++
 3 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2ccf95d7/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index cb78fe4..3937805 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -595,9 +595,11 @@ public class LoggerContext extends AbstractLifeCycle implements org.apache.loggi
      * @param config The Configuration.
      */
     public void updateLoggers(final Configuration config) {
+        final Configuration old = this.configuration;
         for (final Logger logger : loggers.values()) {
             logger.updateConfiguration(config);
         }
+        firePropertyChangeEvent(new PropertyChangeEvent(this, PROPERTY_CONFIG, old, config));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2ccf95d7/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
index fd9b0b0..eb698ab 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.util.List;
 
 import org.apache.logging.log4j.*;
@@ -64,5 +66,18 @@ public class LoggerUpdateTest {
         events = app.getEvents();
         assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
     }
+
+    @Test
+    public void testUpdateLoggersPropertyListeners() throws Exception {
+        final LoggerContext ctx = context.getContext();
+        ctx.addPropertyChangeListener(new PropertyChangeListener() {
+            @Override
+            public void propertyChange(final PropertyChangeEvent evt) {
+                assertEquals(LoggerContext.PROPERTY_CONFIG, evt.getPropertyName());
+                assertSame(ctx, evt.getSource());
+            }
+        });
+        ctx.updateLoggers();
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2ccf95d7/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1313ac9..1895b0f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -208,6 +208,9 @@
       <action issue="LOG4J2-1310" dev="mattsicker" type="fix">
         JndiLookup mindlessly casts to String and should use String.valueOf().
       </action>
+      <action issue="LOG4J2-1206" dev="mattsicker" type="update">
+        org.apache.logging.log4j.core.LoggerContext#updateLoggers should call firePropertyChangeEvent.
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">


[30/50] logging-log4j2 git commit: LOG4J2-1080 version fix

Posted by rp...@apache.org.
LOG4J2-1080 version fix


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: d1d9ac3dae4ce4ef28a2a474c2e4163a5404c22e
Parents: 6af9e31
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:57:19 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:57:19 2016 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/logging/log4j/core/async/EventRoute.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d1d9ac3d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
index 2b8dcd6..c778196 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
@@ -26,7 +26,7 @@ import org.apache.logging.log4j.message.Message;
 /**
  * Enumeration over the different destinations where a log event can be sent.
  *
- * @since 2.5.1
+ * @since 2.6
  */
 public enum EventRoute {
     /**


[21/50] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by rp...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 1ecc28bba0b980a771c863de4028175cd34398fd
Parents: 3245c20 3d4fb63
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 09:50:18 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 09:50:18 2016 -0800

----------------------------------------------------------------------
 .../apache/logging/log4j/core/util/Compare.java | 134 -------------------
 .../log4j/web/appender/ServletAppender.java     |   4 +-
 2 files changed, 1 insertion(+), 137 deletions(-)
----------------------------------------------------------------------



[12/50] logging-log4j2 git commit: LOG4J2-1160 AsyncLoggerDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down (status message at WARN level instead)

Posted by rp...@apache.org.
LOG4J2-1160 AsyncLoggerDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down (status message at WARN level instead)


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 3542dae359052b5b0db75c4e4a7217ba7c910a4e
Parents: bf07950
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 9 08:29:34 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 9 08:29:34 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/AsyncLoggerDisruptor.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3542dae3/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
index c55e1c9..3da2b3e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
@@ -179,7 +179,7 @@ class AsyncLoggerDisruptor {
          */
     private boolean hasLog4jBeenShutDown(final Disruptor<RingBufferLogEvent> aDisruptor) {
         if (aDisruptor == null) { // LOG4J2-639
-            LOGGER.error("Ignoring log event after log4j was shut down");
+            LOGGER.warn("Ignoring log event after log4j was shut down");
             return true;
         }
         return false;
@@ -193,7 +193,7 @@ class AsyncLoggerDisruptor {
             // was shut down, which could cause the publishEvent method to hang and never return.
             disruptor.publishEvent(translator);
         } catch (final NullPointerException npe) {
-            LOGGER.error("[{}] Ignoring log event after log4j was shut down.", contextName);
+            LOGGER.warn("[{}] Ignoring log event after log4j was shut down.", contextName);
         }
     }
 


[11/50] logging-log4j2 git commit: LOG4J2-1160 AsyncLoggerConfigDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down (status message at WARN level instead)

Posted by rp...@apache.org.
LOG4J2-1160 AsyncLoggerConfigDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down (status message at WARN level instead)


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: bf0795017628d9f5bf969bd420c4e458d4b72d90
Parents: c2187bc
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 9 08:29:05 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 9 08:29:05 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLoggerConfigDisruptor.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf079501/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index dc6d296..20e025c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -245,7 +245,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
      */
     private boolean hasLog4jBeenShutDown(final Disruptor<Log4jEventWrapper> aDisruptor) {
         if (aDisruptor == null) { // LOG4J2-639
-            LOGGER.error("Ignoring log event after log4j was shut down");
+            LOGGER.warn("Ignoring log event after log4j was shut down");
             return true;
         }
         return false;
@@ -260,7 +260,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         } catch (final NullPointerException npe) {
             // Note: NPE prevents us from adding a log event to the disruptor after it was shut down,
             // which could cause the publishEvent method to hang and never return.
-            LOGGER.error("Ignoring log event after log4j was shut down.");
+            LOGGER.warn("Ignoring log event after log4j was shut down.");
         }
     }
 


[41/50] logging-log4j2 git commit: LOG4J2-1296 refactor magic numbers to constants

Posted by rp...@apache.org.
LOG4J2-1296 refactor magic numbers to constants


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 50c76834e7fbc878652d8d983738c9369f3158ec
Parents: 69999c2
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 03:22:58 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 03:22:58 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/RingBufferLogEvent.java  | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/50c76834/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 32d73d9..e4c135a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -46,6 +46,8 @@ public class RingBufferLogEvent implements LogEvent {
     public static final Factory FACTORY = new Factory();
 
     private static final long serialVersionUID = 8462119088943934758L;
+    private static final int INITIAL_REUSABLE_MESSAGE_SIZE = 128;
+    private static final int MAX_REUSABLE_MESSAGE_SIZE = 128 * 2 + 2; // resized once from 128 (s=s*2+2)
 
     /**
      * Creates the events that will be put in the RingBuffer.
@@ -56,7 +58,7 @@ public class RingBufferLogEvent implements LogEvent {
         public RingBufferLogEvent newInstance() {
             RingBufferLogEvent result = new RingBufferLogEvent();
             if (Constants.ENABLE_THREADLOCALS) {
-                result.messageText = new StringBuilder(128);
+                result.messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
             }
             return result;
         }
@@ -91,8 +93,8 @@ public class RingBufferLogEvent implements LogEvent {
             buffer.append(stringBuilder);
 
             // ensure that excessively long char[] arrays are not kept in memory forever
-            if (stringBuilder.length() > 518) { // resized twice from 128 (s=s*2+2)
-                stringBuilder.setLength(518);
+            if (stringBuilder.length() > MAX_REUSABLE_MESSAGE_SIZE) {
+                stringBuilder.setLength(MAX_REUSABLE_MESSAGE_SIZE);
                 stringBuilder.trimToSize();
             }
         }
@@ -136,7 +138,7 @@ public class RingBufferLogEvent implements LogEvent {
             if (messageText == null) {
                 // Should never happen:
                 // only happens if user logs a custom reused message when Constants.ENABLE_THREADLOCALS is false
-                messageText = new StringBuilder(128);
+                messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
             }
             messageText.setLength(0);
             ((ReusableMessage) msg).formatTo(messageText);
@@ -340,8 +342,8 @@ public class RingBufferLogEvent implements LogEvent {
         );
 
         // ensure that excessively long char[] arrays are not kept in memory forever
-        if (messageText != null && messageText.length() > 258) { // resized more than once from 128 (s=s*2+2)
-            messageText.setLength(258);
+        if (messageText != null && messageText.length() > MAX_REUSABLE_MESSAGE_SIZE) {
+            messageText.setLength(MAX_REUSABLE_MESSAGE_SIZE);
             messageText.trimToSize();
         }
     }


[40/50] logging-log4j2 git commit: LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional very long messages do not result in large char[] arrays being held by the RingBuffer forever

Posted by rp...@apache.org.
LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional very long messages do not result in large char[] arrays being held by the RingBuffer forever


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 69999c2278bbefdace942ea5de9683226c14b5fe
Parents: 05adeef
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 03:10:31 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/RingBufferLogEvent.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/69999c22/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index e918500..32d73d9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -338,6 +338,12 @@ public class RingBufferLogEvent implements LogEvent {
                 null,
                 0, 0 // nanoTime
         );
+
+        // ensure that excessively long char[] arrays are not kept in memory forever
+        if (messageText != null && messageText.length() > 258) { // resized more than once from 128 (s=s*2+2)
+            messageText.setLength(258);
+            messageText.trimToSize();
+        }
     }
 
     private void writeObject(final java.io.ObjectOutputStream out) throws IOException {


[02/50] logging-log4j2 git commit: Use named constant instead of magic int.

Posted by rp...@apache.org.
Use named constant instead of magic int.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: cc37ea67085aeb6b15c474a66c7ebb62c8b1e2ec
Parents: bc5a809
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 10:24:14 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 10:24:14 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/pattern/DatePatternConverterTest.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cc37ea67/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
index 2b572b1..3455d30 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
@@ -154,7 +154,7 @@ public class DatePatternConverterTest {
         @Override
         public long getTimeMillis() {
             final Calendar cal = Calendar.getInstance();
-            cal.set(2011, 11, 30, 10, 56, 35);
+            cal.set(2011, Calendar.DECEMBER, 30, 10, 56, 35);
             cal.set(Calendar.MILLISECOND, 987);
             return cal.getTimeInMillis();
         }


[26/50] logging-log4j2 git commit: Return null instead of "null".

Posted by rp...@apache.org.
Return null instead of "null".


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 9d0dbe4a65d110c84aee9251d21642498c1cc413
Parents: 5bd76ac
Author: Matt Sicker <bo...@gmail.com>
Authored: Sat Mar 12 11:55:13 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sat Mar 12 11:55:13 2016 -0600

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/lookup/JndiLookup.java   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d0dbe4a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
index 1cd4290..3ceed5d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
@@ -42,7 +42,7 @@ public class JndiLookup extends AbstractLookup {
      * Looks up the value of the JNDI resource.
      * @param event The current LogEvent (is ignored by this StrLookup).
      * @param key  the JNDI resource name to be looked up, may be null
-     * @return The value of the JNDI resource.
+     * @return The String value of the JNDI resource.
      */
     @Override
     public String lookup(final LogEvent event, final String key) {
@@ -52,7 +52,8 @@ public class JndiLookup extends AbstractLookup {
         final String jndiName = convertJndiName(key);
         final JndiManager jndiManager = JndiManager.getDefaultManager();
         try {
-            return String.valueOf(jndiManager.lookup(jndiName));
+            final Object value = jndiManager.lookup(jndiName);
+            return value == null ? null : String.valueOf(value);
         } catch (final NamingException e) {
             LOGGER.warn(LOOKUP, "Error looking up JNDI resource [{}].", jndiName, e);
             return null;


[23/50] logging-log4j2 git commit: Better JUnit assertion.

Posted by rp...@apache.org.
Better JUnit assertion.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: b74ece8c7463cffb95ef0dd5aa12e669fc60ddb5
Parents: e2a8652
Author: ggregory <gg...@apache.org>
Authored: Fri Mar 11 16:35:30 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Fri Mar 11 16:35:30 2016 -0800

----------------------------------------------------------------------
 .../log4j/flume/appender/FlumeEmbeddedAppenderTest.java   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b74ece8c/log4j-flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedAppenderTest.java b/log4j-flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedAppenderTest.java
index 3f6627b..8b2c3e0 100644
--- a/log4j-flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedAppenderTest.java
+++ b/log4j-flume-ng/src/test/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedAppenderTest.java
@@ -132,7 +132,7 @@ public class FlumeEmbeddedAppenderTest {
         EventLogger.logEvent(msg);
 
         final Event event = primary.poll();
-        Assert.assertNotNull(event);
+        Assert.assertNotNull("Event should not be null", event);
         final String body = getBody(event);
         Assert.assertTrue("Channel contained event, but not expected message. Received: " + body,
             body.endsWith("Test Log4j"));
@@ -147,7 +147,7 @@ public class FlumeEmbeddedAppenderTest {
         }
         for (int i = 0; i < 10; ++i) {
             final Event event = primary.poll();
-            Assert.assertNotNull(event);
+            Assert.assertNotNull("Event should not be null", event);
             final String body = getBody(event);
             final String expected = "Test Multiple " + i;
             Assert.assertTrue("Channel contained event, but not expected message. Received: " + body,
@@ -166,7 +166,7 @@ public class FlumeEmbeddedAppenderTest {
         }
         for (int i = 0; i < 10; ++i) {
             final Event event = primary.poll();
-            Assert.assertNotNull(event);
+            Assert.assertNotNull("Event should not be null", event);
             final String body = getBody(event);
             final String expected = "Test Primary " + i;
             Assert.assertTrue("Channel contained event, but not expected message. Received: " + body,
@@ -185,7 +185,7 @@ public class FlumeEmbeddedAppenderTest {
         }
         for (int i = 0; i < 10; ++i) {
             final Event event = alternate.poll();
-            Assert.assertNotNull(event);
+            Assert.assertNotNull("Event should not be null", event);
             final String body = getBody(event);
             final String expected = "Test Alternate " + i;
             /* When running in Gump Flume consistently returns the last event from the primary channel after
@@ -202,7 +202,7 @@ public class FlumeEmbeddedAppenderTest {
         EventLogger.logEvent(msg);
 
         final Event event = primary.poll();
-        Assert.assertNotNull(event);
+        Assert.assertNotNull("Event should not be null", event);
         final String environmentHeader = event.getHeaders().get("environment");
         Assert.assertEquals("local", environmentHeader);
     }


[37/50] logging-log4j2 git commit: LOG4J2-1080 AsyncLogger fixes and optimizations

Posted by rp...@apache.org.
LOG4J2-1080 AsyncLogger fixes and optimizations

- AsyncLogger now tries to publish to the ring buffer and falls back to AsyncEventRouter when the queue is full
- falling back to AsyncEventRouter no longer calls EventRoute.logMessage() but internally switches on the enum to avoid unnecessarily re-populating the translator
- EventRoute.logMessage() implementations for AsyncLogger have been removed
- simplified RingBufferLogEventTranslator initialization
- RingBufferLogEventTranslator thread-related fields are not modified by default unless ThreadNameCachingStrategy is UNCACHED
- optimization for determining whether location should be calculated or not


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: a8bbdcd1f355e98bc89c96c02e057380836dd6e0
Parents: 43cefdd
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:26:36 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:26:36 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLogger.java   | 165 ++++++++-----------
 .../logging/log4j/core/async/EventRoute.java    |   2 -
 2 files changed, 68 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a8bbdcd1/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
index 226ba08..8817b29 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
@@ -74,6 +74,8 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
     private final ThreadLocal<RingBufferLogEventTranslator> threadLocalTranslator = new ThreadLocal<>();
     private final AsyncLoggerDisruptor loggerDisruptor;
 
+    // Reconfigurable. Volatile field nanoClock is always updated later, so no need to make includeLocation volatile.
+    private boolean includeLocation;
     private volatile NanoClock nanoClock; // reconfigurable
 
     /**
@@ -88,6 +90,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
             final AsyncLoggerDisruptor loggerDisruptor) {
         super(context, name, messageFactory);
         this.loggerDisruptor = loggerDisruptor;
+        includeLocation = privateConfig.loggerConfig.isIncludeLocation();
         nanoClock = context.getConfiguration().getNanoClock();
     }
 
@@ -99,6 +102,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
     @Override
     protected void updateConfiguration(Configuration newConfig) {
         super.updateConfiguration(newConfig);
+        includeLocation = privateConfig.loggerConfig.isIncludeLocation();
         nanoClock = newConfig.getNanoClock();
         LOGGER.trace("[{}] AsyncLogger {} uses {}.", getContext().getName(), getName(), nanoClock);
     }
@@ -121,66 +125,10 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
     public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message,
             final Throwable thrown) {
 
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
-        final EventRoute eventRoute = loggerDisruptor.getEventRoute(level);
-        eventRoute.logMessage(this, fqcn, level, marker, message, thrown);
-    }
-
-    /**
-     * LOG4J2-471: prevent deadlock when RingBuffer is full and object being logged calls Logger.log() from its
-     * toString() method
-     *
-     * @param fqcn fully qualified caller name
-     * @param level log level
-     * @param marker optional marker
-     * @param message log message
-     * @param thrown optional exception
-     */
-    void logMessageInCurrentThread(final String fqcn, final Level level, final Marker marker,
-            final Message message, final Throwable thrown) {
-        // bypass RingBuffer and invoke Appender directly
-        final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
-        strategy.log(this, getName(), fqcn, marker, level, message, thrown);
-    }
-
-    /**
-     * Enqueues the specified message to be logged in the background thread.
-     *
-     * @param fqcn fully qualified caller name
-     * @param level log level
-     * @param marker optional marker
-     * @param message log message
-     * @param thrown optional exception
-     */
-    void logMessageInBackgroundThread(final String fqcn, final Level level, final Marker marker,
-            final Message message, final Throwable thrown) {
-
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
         // if the Message instance is reused, there is no point in freezing its message here
-        if (!isReused(message) && !Constants.FORMAT_MESSAGES_IN_BACKGROUND) { // LOG4J2-898: user may choose
+        if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && !isReused(message)) { // LOG4J2-898: user may choose
             message.getFormattedMessage(); // LOG4J2-763: ask message to freeze parameters
         }
-        logInBackground(fqcn, level, marker, message, thrown);
-    }
-
-    private boolean isReused(final Message message) {
-        return message instanceof ReusableMessage;
-    }
-
-    /**
-     * Enqueues the specified log event data for logging in a background thread.
-     *
-     * @param fqcn fully qualified name of the caller
-     * @param level level at which the caller wants to log the message
-     * @param marker message marker
-     * @param message the log message
-     * @param thrown a {@code Throwable} or {@code null}
-     */
-    private void logInBackground(final String fqcn, final Level level, final Marker marker, final Message message,
-            final Throwable thrown) {
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
 
         if (loggerDisruptor.isUseThreadLocals()) {
             logWithThreadLocalTranslator(fqcn, level, marker, message, thrown);
@@ -190,6 +138,10 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
         }
     }
 
+    private boolean isReused(final Message message) {
+        return message instanceof ReusableMessage;
+    }
+
     /**
      * Enqueues the specified log event data for logging in a background thread.
      * <p>
@@ -208,35 +160,35 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
 
         final RingBufferLogEventTranslator translator = getCachedTranslator();
         initTranslator(translator, fqcn, level, marker, message, thrown);
-        loggerDisruptor.enqueueLogMessageInfo(translator);
+        if (!loggerDisruptor.tryPublish(translator)) {
+            handleRingBufferFull(translator);
+        }
     }
 
-    private void initTranslator(final RingBufferLogEventTranslator translator, final String fqcn,
-            final Level level, final Marker marker, final Message message, final Throwable thrown) {
-
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
-        initTranslatorPart1(translator, fqcn, level, marker, message, thrown);
-        initTranslatorPart2(translator, fqcn, message);
+    private void handleRingBufferFull(final RingBufferLogEventTranslator translator) {
+        final EventRoute eventRoute = loggerDisruptor.getEventRoute(translator.level);
+        switch (eventRoute) {
+            case ENQUEUE:
+                loggerDisruptor.enqueueLogMessageInfo(translator);
+                break;
+            case SYNCHRONOUS:
+                logMessageInCurrentThread(translator.fqcn, translator.level, translator.marker, translator.message,
+                        translator.thrown);
+                break;
+            case DISCARD:
+                break;
+            default:
+                throw new IllegalStateException("Unknown EventRoute " + eventRoute);
+        }
     }
 
-    private void initTranslatorPart1(final RingBufferLogEventTranslator translator, final String fqcn,
+    private void initTranslator(final RingBufferLogEventTranslator translator, final String fqcn,
             final Level level, final Marker marker, final Message message, final Throwable thrown) {
 
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
-        translator.setValuesPart1(this, getName(), marker, fqcn, level, message, //
+        translator.setBasicValues(this, name, marker, fqcn, level, message, //
                 // don't construct ThrowableProxy until required
-                thrown);
-    }
-
-    private void initTranslatorPart2(final RingBufferLogEventTranslator translator, final String fqcn,
-            final Message message) {
+                thrown,
 
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
-        final Thread currentThread = Thread.currentThread();
-        translator.setValuesPart2(
                 // config properties are taken care of in the EventHandler thread
                 // in the AsyncLogger#actualAsyncLog method
 
@@ -245,17 +197,33 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
 
                 // needs shallow copy to be fast (LOG4J2-154)
                 ThreadContext.getImmutableStack(), //
-
-                currentThread.getId(), //
-
-                // Thread.currentThread().getName(), //
-                THREAD_NAME_CACHING_STRATEGY.getThreadName(),
-
-                currentThread.getPriority(), //
                 // location (expensive to calculate)
-                calcLocationIfRequested(fqcn),
-                eventTimeMillis(message), nanoClock.nanoTime() //
-                );
+                calcLocationIfRequested(fqcn), //
+                eventTimeMillis(message), //
+                nanoClock.nanoTime() //
+        );
+        // constant check should be optimized out when using default (CACHED)
+        if (THREAD_NAME_CACHING_STRATEGY == ThreadNameCachingStrategy.UNCACHED) {
+            final Thread currentThread = Thread.currentThread();
+            translator.setThreadValues(
+                    currentThread.getId(), //
+                    currentThread.getName(), //
+                    currentThread.getPriority() //
+            );
+        }
+    }
+
+    /**
+     * Returns the caller location if requested, {@code null} otherwise.
+     *
+     * @param fqcn fully qualified caller name.
+     * @return the caller location if requested, {@code null} otherwise.
+     */
+    private StackTraceElement calcLocationIfRequested(String fqcn) {
+        // location: very expensive operation. LOG4J2-153:
+        // Only include if "includeLocation=true" is specified,
+        // exclude if not specified or if "false" was specified.
+        return includeLocation ? Log4jLogEvent.calcLocation(fqcn) : null;
     }
 
     private long eventTimeMillis(final Message message) {
@@ -325,17 +293,20 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
     }
 
     /**
-     * Returns the caller location if requested, {@code null} otherwise.
+     * LOG4J2-471: prevent deadlock when RingBuffer is full and object being logged calls Logger.log() from its
+     * toString() method
      *
-     * @param fqcn fully qualified caller name.
-     * @return the caller location if requested, {@code null} otherwise.
+     * @param fqcn fully qualified caller name
+     * @param level log level
+     * @param marker optional marker
+     * @param message log message
+     * @param thrown optional exception
      */
-    private StackTraceElement calcLocationIfRequested(String fqcn) {
-        // location: very expensive operation. LOG4J2-153:
-        // Only include if "includeLocation=true" is specified,
-        // exclude if not specified or if "false" was specified.
-        final boolean includeLocation = privateConfig.loggerConfig.isIncludeLocation();
-        return includeLocation ? Log4jLogEvent.calcLocation(fqcn) : null;
+    void logMessageInCurrentThread(final String fqcn, final Level level, final Marker marker,
+            final Message message, final Throwable thrown) {
+        // bypass RingBuffer and invoke Appender directly
+        final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
+        strategy.log(this, getName(), fqcn, marker, level, message, thrown);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a8bbdcd1/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
index c778196..ce57008 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
@@ -36,7 +36,6 @@ public enum EventRoute {
         @Override
         public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
                 final Marker marker, final Message message, final Throwable thrown) {
-            asyncLogger.logMessageInBackgroundThread(fqcn, level, marker, message, thrown);
         }
 
         @Override
@@ -56,7 +55,6 @@ public enum EventRoute {
         @Override
         public void logMessage(final AsyncLogger asyncLogger, final String fqcn, final Level level,
                 final Marker marker, final Message message, final Throwable thrown) {
-            asyncLogger.logMessageInCurrentThread(fqcn, level, marker, message, thrown);
         }
 
         @Override


[09/50] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by rp...@apache.org.
Merge remote-tracking branch 'origin/master'


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: a47a2248425e744cb9f4203029f9da89cc8ec900
Parents: 6207ea6 9529448
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 9 08:22:58 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 9 08:22:58 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/EventLoggerTest.java   |  2 +-
 .../apache/logging/log4j/LambdaLoggerTest.java  |  3 +--
 .../logging/log4j/core/LoggerContext.java       |  2 ++
 .../logging/log4j/core/lookup/JndiLookup.java   |  2 +-
 .../logging/log4j/core/LoggerUpdateTest.java    | 15 +++++++++++++
 .../rolling/RollingAppenderSizeTest.java        | 15 +++++--------
 .../log4j/core/lookup/JndiLookupTest.java       | 18 ++++++++++++++++
 .../core/pattern/DatePatternConverterTest.java  |  2 +-
 .../apache/logging/log4j/junit/CleanFiles.java  |  2 +-
 .../log4j/test/appender/AlwaysFailAppender.java | 11 ++++------
 .../log4j/test/appender/DeadlockAppender.java   | 13 ++++--------
 .../log4j/test/appender/FailOnceAppender.java   | 13 ++++--------
 .../log4j/test/appender/InMemoryAppender.java   |  2 --
 .../log4j/test/appender/ListAppender.java       |  6 +-----
 .../test/appender/UsesLoggingAppender.java      | 22 +++++++-------------
 .../log4j/web/Log4jWebInitializerImpl.java      |  5 +++--
 src/changes/changes.xml                         | 14 ++++++++++++-
 src/site/xdoc/manual/configuration.xml.vm       |  4 ++++
 18 files changed, 85 insertions(+), 66 deletions(-)
----------------------------------------------------------------------



[33/50] logging-log4j2 git commit: LOG4J2-1080 updated AsyncAppender after removing support for dropping events on partially full queue

Posted by rp...@apache.org.
LOG4J2-1080 updated AsyncAppender after removing support for dropping events on partially full queue


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 76067f2d9e8b32fe305a650aa821b77797791a03
Parents: e91ea51
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:59:10 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:59:10 2016 +1100

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/appender/AsyncAppender.java   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/76067f2d/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
index c9d8326..31bdfbf 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
@@ -111,7 +111,7 @@ public final class AsyncAppender extends AbstractAppender {
         } else if (errorRef == null) {
             throw new ConfigurationException("No appenders are available for AsyncAppender " + getName());
         }
-        asyncEventRouter = AsyncEventRouterFactory.create(queueSize);
+        asyncEventRouter = AsyncEventRouterFactory.create();
 
         thread.start();
         super.start();
@@ -160,8 +160,7 @@ public final class AsyncAppender extends AbstractAppender {
 
     private void logEvent(final Log4jLogEvent logEvent) {
         final Level logLevel = logEvent.getLevel();
-        final int remainingCapacity = getQueueRemainingCapacity();
-        final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logLevel, queueSize, remainingCapacity);
+        final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logLevel);
         route.logMessage(this, logEvent);
     }
 


[46/50] logging-log4j2 git commit: Reference Java 7, not 6 for jconsole.

Posted by rp...@apache.org.
Reference Java 7, not 6 for jconsole.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 8e13c98f6534c1d45ce92bb1420de7893902433a
Parents: d5f7c94
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 15 02:08:09 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 15 02:08:09 2016 -0700

----------------------------------------------------------------------
 log4j-jmx-gui/pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8e13c98f/log4j-jmx-gui/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-jmx-gui/pom.xml b/log4j-jmx-gui/pom.xml
index 0b4f07f..b460514 100644
--- a/log4j-jmx-gui/pom.xml
+++ b/log4j-jmx-gui/pom.xml
@@ -194,7 +194,7 @@
         <dependency>
           <groupId>com.sun</groupId>
           <artifactId>jconsole</artifactId>
-          <version>1.6.0</version>
+          <version>1.7.0</version>
           <scope>system</scope>
           <systemPath>${java.home}/../lib/jconsole.jar</systemPath>
           <optional>true</optional>
@@ -213,7 +213,7 @@
         <dependency>
           <groupId>com.sun</groupId>
           <artifactId>jconsole</artifactId>
-          <version>1.6.0</version>
+          <version>1.7.0</version>
           <scope>system</scope>
           <systemPath>${java.home}/../Classes/jconsole.jar</systemPath>
           <optional>true</optional>


[08/50] logging-log4j2 git commit: LOG4J2-1160 AsyncLoggerDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down

Posted by rp...@apache.org.
LOG4J2-1160 AsyncLoggerDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 6207ea6b8545e89ca82e39b09d3552b8d638e0f4
Parents: f1e5063
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 9 08:22:36 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 9 08:22:36 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/AsyncLoggerDisruptor.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6207ea6b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
index 1188b73..c55e1c9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
@@ -179,7 +179,7 @@ class AsyncLoggerDisruptor {
          */
     private boolean hasLog4jBeenShutDown(final Disruptor<RingBufferLogEvent> aDisruptor) {
         if (aDisruptor == null) { // LOG4J2-639
-            LOGGER.fatal("Ignoring log event after log4j was shut down");
+            LOGGER.error("Ignoring log event after log4j was shut down");
             return true;
         }
         return false;
@@ -193,7 +193,7 @@ class AsyncLoggerDisruptor {
             // was shut down, which could cause the publishEvent method to hang and never return.
             disruptor.publishEvent(translator);
         } catch (final NullPointerException npe) {
-            LOGGER.fatal("[{}] Ignoring log event after log4j was shut down.", contextName);
+            LOGGER.error("[{}] Ignoring log event after log4j was shut down.", contextName);
         }
     }
 


[45/50] logging-log4j2 git commit: LOG4J2-1295 Added automated GC-free test. Still @Ignored as of now because the API creates vararg arrays so the test fails.

Posted by rp...@apache.org.
LOG4J2-1295 Added automated GC-free test. Still @Ignored as of now because the API creates vararg arrays so the test fails.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 52d04e0779eef09d0826c800cdc0874eea4960e5
Parents: 575cd5b
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 17:25:40 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 17:25:40 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/GcFreeLoggingTest.java   | 131 +++++++++++++++++++
 1 file changed, 131 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/52d04e07/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
new file mode 100644
index 0000000..2cca348
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core;
+
+import java.io.File;
+import java.net.URL;
+import java.nio.file.Files;
+
+import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
+import com.google.monitoring.runtime.instrumentation.Sampler;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
+import org.apache.logging.log4j.core.util.Constants;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Verifies steady state logging is GC-free.
+ *
+ * @see <a href="https://github.com/google/allocation-instrumenter">https://github.com/google/allocation-instrumenter</a>
+ */
+public class GcFreeLoggingTest {
+
+    // ignored: test still fails because of vararg arrays
+    @Ignore
+    @Test
+    public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
+        final String javaHome = System.getProperty("java.home");
+        final String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
+        final String classpath = System.getProperty("java.class.path");
+        final String javaagent = "-javaagent:" + agentJar();
+
+        final File tempFile = File.createTempFile("allocations", ".txt");
+        tempFile.deleteOnExit();
+
+        final ProcessBuilder builder = new ProcessBuilder( //
+                javaBin, javaagent, "-cp", classpath, GcFreeLoggingTest.class.getName());
+        builder.redirectError(ProcessBuilder.Redirect.to(tempFile));
+        builder.redirectOutput(ProcessBuilder.Redirect.to(tempFile));
+        final Process process = builder.start();
+        process.waitFor();
+        process.exitValue();
+
+        final String output = new String(Files.readAllBytes(tempFile.toPath()));
+        assertEquals("", output);
+    }
+
+    /**
+     * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
+     */
+    public static void main(String[] args) throws Exception {
+        System.setProperty("log4j2.enable.threadlocals", "true");
+        System.setProperty("log4j2.is.webapp", "false");
+        System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
+        System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
+
+        assertTrue("Constants.ENABLE_THREADLOCALS", Constants.ENABLE_THREADLOCALS);
+        assertFalse("Constants.IS_WEB_APP", Constants.IS_WEB_APP);
+
+        // initialize LoggerContext etc.
+        // This is not steady-state logging and will allocate objects.
+        final Logger logger = LogManager.getLogger(GcFreeLoggingTest.class.getName());
+        logger.debug("debug not set");
+        logger.error("Sample error message");
+        logger.error("Test parameterized message {}", "param");
+
+        // BlockingWaitStrategy uses ReentrantLock which allocates Node objects. Ignore this.
+        final String[] exclude = new String[] {
+                "java/util/concurrent/locks/AbstractQueuedSynchronizer$Node", //
+                "com/google/monitoring/runtime/instrumentation/Sampler", //
+        };
+        final Sampler sampler = new Sampler() {
+            public void sampleAllocation(int count, String desc, Object newObj, long size) {
+                for (int i = 0; i < exclude.length; i++) {
+                    if (exclude[i].equals(desc)) {
+                        return; // exclude
+                    }
+                }
+                System.out.println("I just allocated the object " + newObj +
+                        " of type " + desc + " whose size is " + size);
+                if (count != -1) {
+                    System.out.println("It's an array of size " + count);
+                }
+
+                // uncomment to get a stack trace and see which line caused allocation
+                //new RuntimeException().printStackTrace();
+            }
+        };
+        Thread.sleep(500);
+        AllocationRecorder.addSampler(sampler);
+
+        // now do some steady-state logging
+        final int ITERATIONS = 5;
+        for (int i = 0; i < ITERATIONS; i++) {
+            logger.error("Test message");
+            logger.error("Test parameterized message {}", "param");
+            logger.error("Test parameterized message {}{}", "param", "param2");
+            logger.error("Test parameterized message {}{}{}", "param", "param2", "abc");
+        }
+        AllocationRecorder.removeSampler(sampler);
+        Thread.sleep(50);
+    }
+
+    private static File agentJar() {
+        final String name = AllocationRecorder.class.getName();
+        final URL url = AllocationRecorder.class.getResource("/" + name.replace('.', '/').concat(".class"));
+        if (url == null) {
+            throw new IllegalStateException("Could not find url for " + name);
+        }
+        final String temp = url.toString();
+        final String path = temp.substring("jar:file:/".length(), temp.indexOf('!'));
+        return new File(path);
+    }
+}


[17/50] logging-log4j2 git commit: [LOG4J2-63] Support configuration from version 1.x log4j.properties. Partial support for EnhancedPatternLayout (defaults only).

Posted by rp...@apache.org.
[LOG4J2-63] Support configuration from version 1.x log4j.properties.
Partial support for EnhancedPatternLayout (defaults only).

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 0d2cfbe90fad7f580e6aa1a4d87c4a0855f14610
Parents: d6c916b
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 00:57:46 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 00:57:46 2016 -0800

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationFactory.java |  4 ++++
 .../config/Log4j1ConfigurationFactoryTest.java   |  6 ++++++
 ...og4j-console-EnhancedPatternLayout.properties | 19 +++++++++++++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0d2cfbe9/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 4dcad77..fc07c1c 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -112,6 +112,10 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
                 appenderBuilder.add(newPatternLayout(builder, cpValue));
                 break;
             }
+            case "org.apache.log4j.EnhancedPatternLayout": {
+                appenderBuilder.add(newPatternLayout(builder, cpValue));
+                break;
+            }
             case "org.apache.log4j.SimpleLayout": {
                 appenderBuilder.add(newPatternLayout(builder, "%level - %m%n"));
                 break;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0d2cfbe9/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 013bb74..3212db0 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -51,6 +51,12 @@ public class Log4j1ConfigurationFactoryTest {
     }
 
     @Test
+    public void testConsoleEnhancedPatternLayout() throws Exception {
+        final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-EnhancedPatternLayout.properties");
+        Assert.assertEquals("%d{ISO8601} [%t][%c] %-5p: %m%n", layout.getConversionPattern());
+    }
+
+    @Test
     public void testConsoleHtmlLayout() throws Exception {
         final Layout<?> layout = testConsole("config-1.2/log4j-console-HtmlLayout.properties");
         Assert.assertTrue(layout instanceof HtmlLayout);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0d2cfbe9/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
new file mode 100644
index 0000000..ab61518
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
@@ -0,0 +1,19 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.EnhancedPatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p: %m%n
+
+log4j.logger.com.example.foo = DEBUG


[43/50] logging-log4j2 git commit: No need to call isTraceEnabled() if the message is null. This means the traceEnter() call returned null because isTraceEnabled() returned null.

Posted by rp...@apache.org.
No need to call isTraceEnabled() if the message is null. This means the
traceEnter() call returned null because isTraceEnabled() returned null.

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: d5f7c94f89a5492092764e154adabe4aa12e6a29
Parents: b334215
Author: ggregory <gg...@apache.org>
Authored: Mon Mar 14 18:37:55 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Mon Mar 14 18:37:55 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/spi/AbstractLogger.java   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d5f7c94f/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index b190535..244b8e7 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@ -1431,14 +1431,16 @@ public abstract class AbstractLogger implements ExtendedLogger, Serializable {
 
     @Override
     public void traceExit(final EntryMessage message) {
-        if (isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
+        // If the message is null, traceEnter returned null because flow logging was disabled, we can optimize out calling isEnabled().
+        if (message != null && isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
             logMessage(FQCN, Level.TRACE, EXIT_MARKER, flowMessageFactory.newExitMessage(message), null);
         }
     }
 
     @Override
     public <R> R traceExit(final EntryMessage message, final R result) {
-        if (isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
+        // If the message is null, traceEnter returned null because flow logging was disabled, we can optimize out calling isEnabled().
+        if (message != null && isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
             logMessage(FQCN, Level.TRACE, EXIT_MARKER, flowMessageFactory.newExitMessage(result, message), null);
         }
         return result;
@@ -1446,7 +1448,8 @@ public abstract class AbstractLogger implements ExtendedLogger, Serializable {
 
     @Override
     public <R> R traceExit(final Message message, final R result) {
-        if (isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
+        // If the message is null, traceEnter returned null because flow logging was disabled, we can optimize out calling isEnabled().
+        if (message != null && isEnabled(Level.TRACE, EXIT_MARKER, message, null)) {
             logMessage(FQCN, Level.TRACE, EXIT_MARKER, flowMessageFactory.newExitMessage(result, message), null);
         }
         return result;


[39/50] logging-log4j2 git commit: LOG4J2-1080 updated change log after removing support for dropping events on partially full queue

Posted by rp...@apache.org.
LOG4J2-1080 updated change log after removing support for dropping events on partially full queue


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 05adeefad5519abe89c99788a74a40480e0f869d
Parents: 3be541c
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:43:16 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:43:16 2016 +1100

----------------------------------------------------------------------
 src/changes/changes.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/05adeefa/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 686cc37..3d56a5a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,7 +92,7 @@
       </action>
       <action issue="LOG4J2-1080" dev="rpopma" type="update">
         Added option to discard events below a certain log level if the async logger ring buffer
-        or async appender queue remaining capacity falls below a certain ratio.
+        or async appender queue is full.
       </action>
       <action issue="LOG4J2-1237" dev="ggregory" type="add" due-to="Mike Calmus, Gary Gregory">
         Make PatternLayout header and footer accept a pattern.


[28/50] logging-log4j2 git commit: Add @SafeVarargs

Posted by rp...@apache.org.
Add @SafeVarargs

This can be backported to commons when they require Java 1.7+


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 2c70b441dfe1653f278a05ef7c6066b442d8daeb
Parents: f5a69e8
Author: Matt Sicker <bo...@gmail.com>
Authored: Mon Mar 14 09:11:30 2016 -0500
Committer: Matt Sicker <bo...@gmail.com>
Committed: Mon Mar 14 09:11:30 2016 -0500

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/util/ObjectArrayIterator.java     | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2c70b441/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
index 9f9897e..db8fdd9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ObjectArrayIterator.java
@@ -51,6 +51,7 @@ public class ObjectArrayIterator<E> implements /*Resettable*/ Iterator<E> {
      * @param array the array to iterate over
      * @throws NullPointerException if <code>array</code> is <code>null</code>
      */
+    @SafeVarargs
     public ObjectArrayIterator(final E... array) {
         this(array, 0, array.length);
     }


[03/50] logging-log4j2 git commit: LOG4J2-1133 - Add JNDI lookup documentation.

Posted by rp...@apache.org.
LOG4J2-1133 - Add JNDI lookup documentation.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: ed6c608abe735f3b04cc979ae25e6d12121703a8
Parents: cc37ea6
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 11:10:29 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 11:10:29 2016 -0600

----------------------------------------------------------------------
 src/changes/changes.xml                   | 5 ++++-
 src/site/xdoc/manual/configuration.xml.vm | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ed6c608a/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1543f45..61006a1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -200,7 +200,10 @@
         Remove need to pre-specify appender et al. identifiers in property file config format.
       </action>
       <action issue="LOG4J2-1050" dev="mattsicker" type="fix" due-to="Adam Retter">
-        Add a Log4jLookup class to help write log files relative to log4j2.xml
+        Add a Log4jLookup class to help write log files relative to log4j2.xml.
+      </action>
+      <action issue="LOG4J2-1133" dev="mattsicker" type="add">
+        Add JNDI lookup documentation.
       </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ed6c608a/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index 4bf5247..5e0a5fb 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -974,6 +974,10 @@ rootLogger.appenderRef.stdout.ref = STDOUT
                 <td>System environment variables</td>
               </tr>
               <tr>
+                <td>jndi</td>
+                <td>A value set in the default JNDI Context.</td>
+              </tr>
+              <tr>
                 <td>jvmrunargs</td>
                 <td>
                   A JVM input argument accessed through JMX, but not a main argument;


[07/50] logging-log4j2 git commit: Call deleteDir only when test succeeds.

Posted by rp...@apache.org.
Call deleteDir only when test succeeds.

Should help us determine if the bz2 file created is actually valid or not.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 95294481eb8a7767c067d28d880f5d7f946eab5d
Parents: 04a9ce6
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 15:00:11 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 15:00:11 2016 -0600

----------------------------------------------------------------------
 .../appender/rolling/RollingAppenderSizeTest.java    | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/95294481/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
index 4b0726c..fce9fb4 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java
@@ -30,17 +30,16 @@ import org.apache.commons.compress.utils.IOUtils;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.util.Closer;
 import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
-import static org.apache.logging.log4j.hamcrest.Descriptors.*;
-import static org.apache.logging.log4j.hamcrest.FileMatchers.*;
-import static org.hamcrest.Matchers.*;
-
+import static org.apache.logging.log4j.hamcrest.Descriptors.that;
+import static org.apache.logging.log4j.hamcrest.FileMatchers.hasName;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.hasItemInArray;
 import static org.junit.Assert.*;
 
 /**
@@ -82,11 +81,6 @@ public class RollingAppenderSizeTest {
         this.logger = this.init.getLogger(RollingAppenderSizeTest.class.getName());
     }
 
-    @After
-    public void tearDown() throws Exception {
-        deleteDir();
-    }
-
     @Test
     public void testAppender() throws Exception {
         for (int i = 0; i < 100; ++i) {
@@ -127,6 +121,7 @@ public class RollingAppenderSizeTest {
                 }
             }
         }
+        deleteDir();
     }
 
     private static void deleteDir() {


[48/50] logging-log4j2 git commit: Update Maven Core from 3.2.5 to the current 3.3.9 which updates the test dep Google Guava from 16.0.1 to 19.0 to resolve some other dependency hell I am seeing in a downstream project (of mine).

Posted by rp...@apache.org.
Update Maven Core from 3.2.5 to the current 3.3.9 which updates the test
dep Google Guava from 16.0.1 to 19.0 to resolve some other dependency
hell I am seeing in a downstream project (of mine).

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 6ba91a3c24df320bd8c6cf6a96668ce8ffe0e3c6
Parents: ba5cf45
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 15 02:29:21 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 15 02:29:21 2016 -0700

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6ba91a3c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b923766..3c02bae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -275,7 +275,7 @@
       <dependency>
         <groupId>org.apache.maven</groupId>
         <artifactId>maven-core</artifactId>
-        <version>3.2.5</version>
+        <version>3.3.9</version>
       </dependency>
       <dependency>
         <groupId>commons-codec</groupId>


[10/50] logging-log4j2 git commit: LOG4J2-1160 AsyncLoggerConfigDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down

Posted by rp...@apache.org.
LOG4J2-1160 AsyncLoggerConfigDisruptor should not log status message at FATAL level when logging is attempted after the Disruptor was shut down


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: c2187bc69ad1112319e6339290c52d7a557c3e96
Parents: a47a224
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 9 08:24:03 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 9 08:24:03 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLoggerConfigDisruptor.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c2187bc6/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
index f536d79..dc6d296 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
@@ -245,7 +245,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
      */
     private boolean hasLog4jBeenShutDown(final Disruptor<Log4jEventWrapper> aDisruptor) {
         if (aDisruptor == null) { // LOG4J2-639
-            LOGGER.fatal("Ignoring log event after log4j was shut down");
+            LOGGER.error("Ignoring log event after log4j was shut down");
             return true;
         }
         return false;
@@ -260,7 +260,7 @@ public class AsyncLoggerConfigDisruptor implements AsyncLoggerConfigDelegate {
         } catch (final NullPointerException npe) {
             // Note: NPE prevents us from adding a log event to the disruptor after it was shut down,
             // which could cause the publishEvent method to hang and never return.
-            LOGGER.fatal("Ignoring log event after log4j was shut down.");
+            LOGGER.error("Ignoring log event after log4j was shut down.");
         }
     }
 


[35/50] logging-log4j2 git commit: LOG4J2-1080 AsyncLoggerDisruptor now supports trying to enqueue log events; signalling false when the queue is full

Posted by rp...@apache.org.
LOG4J2-1080 AsyncLoggerDisruptor now supports trying to enqueue log events; signalling false when the queue is full


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 32e30697d0638dc9139591e85658e21758920843
Parents: 7a7f5e4
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:04:39 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:04:39 2016 +1100

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLoggerDisruptor.java       | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/32e30697/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
index 3da2b3e..cb78ce6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
@@ -83,7 +83,7 @@ class AsyncLoggerDisruptor {
         final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLogger.WaitStrategy");
         executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("AsyncLogger[" + contextName + "]"));
         backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor);
-        asyncEventRouter = AsyncEventRouterFactory.create(ringBufferSize);
+        asyncEventRouter = AsyncEventRouterFactory.create();
 
         disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, executor, ProducerType.MULTI,
                 waitStrategy);
@@ -164,7 +164,7 @@ class AsyncLoggerDisruptor {
         if (remainingCapacity < 0) {
             return EventRoute.DISCARD;
         }
-        return asyncEventRouter.getRoute(backgroundThreadId, logLevel, ringBufferSize, remainingCapacity);
+        return asyncEventRouter.getRoute(backgroundThreadId, logLevel);
     }
 
     private int remainingDisruptorCapacity() {
@@ -185,6 +185,10 @@ class AsyncLoggerDisruptor {
         return false;
     }
 
+    public boolean tryPublish(final RingBufferLogEventTranslator translator) {
+        return disruptor.getRingBuffer().tryPublishEvent(translator);
+    }
+
     void enqueueLogMessageInfo(final RingBufferLogEventTranslator translator) {
         // LOG4J2-639: catch NPE if disruptor field was set to null in stop()
         try {


[27/50] logging-log4j2 git commit: LOG4J2-1080 make Logger name field directly readable by subclasses

Posted by rp...@apache.org.
LOG4J2-1080 make Logger name field directly readable by subclasses


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: f5a69e8f68aa1d1f9d3bd22d8dd63322184faf84
Parents: 9d0dbe4
Author: rpopma <rp...@apache.org>
Authored: Mon Mar 14 21:49:50 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Mon Mar 14 21:49:50 2016 +1100

----------------------------------------------------------------------
 .../src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f5a69e8f/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index c982294..b190535 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@ -91,7 +91,7 @@ public abstract class AbstractLogger implements ExtendedLogger, Serializable {
     private static final String THROWING = "Throwing";
     private static final String CATCHING = "Catching";
 
-    private final String name;
+    protected final String name;
     private final MessageFactory messageFactory;
     private final FlowMessageFactory flowMessageFactory;
 


[44/50] logging-log4j2 git commit: LOG4J2-1295 automated GC-free test: add dependency for google allocation instrumenter

Posted by rp...@apache.org.
LOG4J2-1295 automated GC-free test: add dependency for google allocation instrumenter


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 575cd5bc216e2c8c355abadff343e8ab90ae7432
Parents: d5f7c94
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 17:24:22 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 17:24:22 2016 +1100

----------------------------------------------------------------------
 log4j-core/pom.xml | 6 ++++++
 pom.xml            | 6 ++++++
 2 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/575cd5bc/log4j-core/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index 7ff68cd..d149fe2 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -273,6 +273,12 @@
       <version>2.4.5</version>
       <scope>test</scope>
     </dependency>
+    <!-- GC-free -->
+    <dependency>
+      <groupId>com.google.code.java-allocation-instrumenter</groupId>
+      <artifactId>java-allocation-instrumenter</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/575cd5bc/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c5eb74e..b923766 100644
--- a/pom.xml
+++ b/pom.xml
@@ -730,6 +730,12 @@
         <artifactId>commons-csv</artifactId>
         <version>1.2</version>
       </dependency>
+      <!-- GC-free -->
+      <dependency>
+        <groupId>com.google.code.java-allocation-instrumenter</groupId>
+        <artifactId>java-allocation-instrumenter</artifactId>
+        <version>3.0</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <build>


[22/50] logging-log4j2 git commit: LOG4J2-1169 - PatternLayout: Possible variable substitution in equals substitution parameter

Posted by rp...@apache.org.
LOG4J2-1169 - PatternLayout: Possible variable substitution in equals substitution parameter


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: e2a8652691143b5713e0b6872210da1d049a20a3
Parents: 1ecc28b
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Mar 9 14:14:26 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Mar 9 14:14:35 2016 -0600

----------------------------------------------------------------------
 .../pattern/EqualsReplacementConverter.java     | 48 ++++++++++-----
 .../log4j/core/layout/PatternLayoutTest.java    | 22 +++++++
 .../pattern/EqualsReplacementConverterTest.java | 63 +++++++++++++++++---
 src/changes/changes.xml                         |  3 +
 4 files changed, 113 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e2a86526/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
index 2534b5d..bb8464c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverter.java
@@ -33,10 +33,8 @@ public final class EqualsReplacementConverter extends LogEventPatternConverter {
     /**
      * Gets an instance of the class.
      *
-     * @param config
-     *            The current Configuration.
-     * @param options
-     *            pattern options, an array of three elements: pattern, testString, and substitution.
+     * @param config  The current Configuration.
+     * @param options pattern options, an array of three elements: pattern, testString, and substitution.
      * @return instance of class.
      */
     public static EqualsReplacementConverter newInstance(final Configuration config, final String[] options) {
@@ -59,7 +57,7 @@ public final class EqualsReplacementConverter extends LogEventPatternConverter {
         final String p = options[1];
         final PatternParser parser = PatternLayout.createPatternParser(config);
         final List<PatternFormatter> formatters = parser.parse(options[0]);
-        return new EqualsReplacementConverter(formatters, p, options[2]);
+        return new EqualsReplacementConverter(formatters, p, options[2], parser);
     }
 
     private final List<PatternFormatter> formatters;
@@ -68,22 +66,23 @@ public final class EqualsReplacementConverter extends LogEventPatternConverter {
 
     private final String testString;
 
+    private final PatternParser parser;
+
     /**
      * Construct the converter.
-     * 
-     * @param formatters
-     *            The PatternFormatters to generate the text to manipulate.
-     * @param testString
-     *            The test string.
-     * @param substitution
-     *            The substitution string.
+     *
+     * @param formatters   The PatternFormatters to generate the text to manipulate.
+     * @param testString   The test string.
+     * @param substitution The substitution string.
+     * @param parser       The PatternParser.
      */
     private EqualsReplacementConverter(final List<PatternFormatter> formatters, final String testString,
-            final String substitution) {
+                                       final String substitution, PatternParser parser) {
         super("equals", "equals");
         this.testString = testString;
         this.substitution = substitution;
         this.formatters = formatters;
+        this.parser = parser;
     }
 
     /**
@@ -96,6 +95,27 @@ public final class EqualsReplacementConverter extends LogEventPatternConverter {
             formatter.format(event, buf);
         }
         final String string = buf.toString();
-        toAppendTo.append(testString.equals(string) ? substitution : string);
+        toAppendTo.append(testString.equals(string) ? parseSubstitution(event) : string);
+    }
+
+    /**
+     * Returns the parsed substitution text.
+     *
+     * @param event the current log event
+     * @return the parsed substitution text
+     */
+    String parseSubstitution(final LogEvent event) {
+        final StringBuilder substitutionBuffer = new StringBuilder();
+        // check if substitution needs to be parsed
+        if (substitution.contains("%")) {
+            // parse substitution pattern
+            final List<PatternFormatter> substitutionFormatters = parser.parse(substitution);
+            for (final PatternFormatter formatter : substitutionFormatters) {
+                formatter.format(event, substitutionBuffer);
+            }
+        } else {
+            substitutionBuffer.append(substitution);
+        }
+        return substitutionBuffer.toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e2a86526/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
index 2184599..988b42b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
@@ -288,6 +288,28 @@ public class PatternLayoutTest {
     }
 
     @Test
+    public void testEqualsMarkerWithMessageSubstitution() throws Exception {
+        // replace "[]" with the empty string
+        final PatternLayout layout = PatternLayout.newBuilder().withPattern("[%logger]%equals{[%marker]}{[]}{[%msg]}")
+            .withConfiguration(ctx.getConfiguration()).build();
+        // Not empty marker
+        final LogEvent event1 = Log4jLogEvent.newBuilder() //
+            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
+            .setLevel(Level.INFO) //
+            .setMarker(MarkerManager.getMarker("TestMarker"))
+            .setMessage(new SimpleMessage("Hello, world!")).build();
+        final byte[] result1 = layout.toByteArray(event1);
+        assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker]", new String(result1));
+        // empty marker
+        final LogEvent event2 = Log4jLogEvent.newBuilder() //
+            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
+            .setLevel(Level.INFO)
+            .setMessage(new SimpleMessage("Hello, world!")).build();
+        final byte[] result2 = layout.toByteArray(event2);
+        assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest][Hello, world!]", new String(result2));
+    }
+
+    @Test
     public void testSpecialChars() throws Exception {
         final PatternLayout layout = PatternLayout.newBuilder().withPattern("\\\\%level\\t%msg\\n\\t%logger\\r\\n\\f")
                 .withConfiguration(ctx.getConfiguration()).build();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e2a86526/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverterTest.java
index 5534662..642ed16 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EqualsReplacementConverterTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
-import static org.junit.Assert.assertEquals;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -26,11 +24,15 @@ import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.util.Strings;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 /**
  *
  */
 public class EqualsReplacementConverterTest {
 
+    private static final String TEST_MESSAGE = "This is a test";
+
     @Test
     public void testMarkerReplacement() {
         testReplacement("%marker", Strings.EMPTY);
@@ -46,18 +48,61 @@ public class EqualsReplacementConverterTest {
         testReplacement("%logger", "[" + EqualsReplacementConverterTest.class.getName() + "]");
     }
 
-    private void testReplacement(String tag, String expectedValue) {
+    @Test
+    public void testMarkerReplacementWithMessage() {
+        testReplacement(TEST_MESSAGE, new String[]{"[%marker]", "[]", "%msg"});
+    }
+
+    private void testReplacement(final String tag, final String expectedValue) {
+        final String[] options = new String[]{"[" + tag + "]", "[]", expectedValue};
+        testReplacement(expectedValue, options);
+    }
+
+    private void testReplacement(final String expectedValue, final String[] options) {
         final LogEvent event = Log4jLogEvent.newBuilder() //
-                .setLoggerName(EqualsReplacementConverterTest.class.getName()) //
-                .setLevel(Level.DEBUG) //
-                .setMessage(new SimpleMessage("This is a test")) //
-                .build();
+            .setLoggerName(EqualsReplacementConverterTest.class.getName()) //
+            .setLevel(Level.DEBUG) //
+            .setMessage(new SimpleMessage(TEST_MESSAGE)) //
+            .build();
         final StringBuilder sb = new StringBuilder();
         final LoggerContext ctx = LoggerContext.getContext();
-        final String[] options = new String[] { "[" + tag + "]", "[]", expectedValue };
         final EqualsReplacementConverter converter = EqualsReplacementConverter.newInstance(ctx.getConfiguration(),
-                options);
+            options);
         converter.format(event, sb);
         assertEquals(expectedValue, sb.toString());
     }
+
+    @Test
+    public void testParseSubstitutionWithPattern() {
+        testParseSubstitution("%msg", TEST_MESSAGE);
+    }
+
+    @Test
+    public void testParseSubstitutionWithoutPattern() {
+        String substitution = "test";
+        testParseSubstitution(substitution, substitution);
+    }
+
+    @Test
+    public void testParseSubstitutionEmpty() {
+        testParseSubstitution("", "");
+    }
+
+    @Test
+    public void testParseSubstitutionWithWhiteSpaces() {
+        testParseSubstitution(" ", " ");
+    }
+
+    private void testParseSubstitution(final String substitution, final String expected) {
+        final LogEvent event = Log4jLogEvent.newBuilder()
+            .setLoggerName(EqualsReplacementConverterTest.class.getName())
+            .setLevel(Level.DEBUG)
+            .setMessage(new SimpleMessage(TEST_MESSAGE))
+            .build();
+        final LoggerContext ctx = LoggerContext.getContext();
+        final EqualsReplacementConverter converter = EqualsReplacementConverter.newInstance(ctx.getConfiguration(),
+            new String[]{"[%marker]", "[]", substitution});
+        final String actual = converter.parseSubstitution(event);
+        assertEquals(expected, actual);
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e2a86526/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 68e3ec8..686cc37 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -214,6 +214,9 @@
       <action issue="LOG4J2-248" dev="mattsicker" type="fix">
         Log4jWebInitializerImpl: Use Thread instead of Class for fallback classloader.
       </action>
+      <action issue="LOG4J2-1169" dev="mattsicker" type="add" due-to="Gerald Kritzinger">
+        PatternLayout: Possible variable substitution in equals substitution parameter.
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">


[49/50] logging-log4j2 git commit: Merge remote-tracking branch 'remotes/origin/master' into LOG4J2-1278-gc-free-logger

Posted by rp...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into LOG4J2-1278-gc-free-logger


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 7b9077c3bdb9b21b03a9e8bdfe8f55ddc5eeb506
Parents: 2faae9c 6ba91a3
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 16 17:06:17 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 16 17:06:17 2016 +1100

----------------------------------------------------------------------
 log4j-1.2-api/pom.xml                           |   5 +
 .../config/Log4j1ConfigurationFactory.java      | 314 +++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  88 +++
 ...g4j-console-EnhancedPatternLayout.properties |  19 +
 .../log4j-console-HtmlLayout.properties         |  18 +
 .../log4j-console-PatternLayout.properties      |  19 +
 .../log4j-console-SimpleLayout.properties       |  18 +
 .../log4j-console-TTCCLayout.properties         |  18 +
 .../log4j-console-XmlLayout.properties          |  18 +
 .../logging/log4j/message/ObjectMessage.java    |   6 +-
 .../logging/log4j/message/ReusableMessage.java  |   4 +
 .../log4j/message/ReusableMessageFactory.java   | 123 +++++
 .../log4j/message/ReusableObjectMessage.java    |  94 ++++
 .../message/ReusableParameterizedMessage.java   | 249 ++++-----
 .../ReusableParameterizedMessageFactory.java    | 127 -----
 .../log4j/message/ReusableSimpleMessage.java    |  60 ++
 .../logging/log4j/spi/AbstractLogger.java       |  17 +-
 .../logging/log4j/util/PropertiesUtil.java      |  22 +
 .../apache/logging/log4j/EventLoggerTest.java   |   2 +-
 .../apache/logging/log4j/LambdaLoggerTest.java  |   3 +-
 .../log4j/message/ParameterFormatterTest.java   | 193 +++++++
 .../message/ReusableObjectMessageTest.java      | 122 ++++
 .../ReusableParameterizedMessageTest.java       |  59 ++
 .../message/ReusableSimpleMessageTest.java      | 122 ++++
 .../logging/log4j/util/PropertiesUtilTest.java  |  65 +++
 .../resources/PropertiesUtilTest.properties     |  29 +
 log4j-core/pom.xml                              |   6 +
 .../org/apache/logging/log4j/core/Appender.java |   8 +
 .../org/apache/logging/log4j/core/Layout.java   |   3 +-
 .../logging/log4j/core/LoggerContext.java       |   2 +
 .../log4j/core/appender/AsyncAppender.java      |   5 +-
 .../log4j/core/appender/mom/JmsAppender.java    |  10 +-
 .../log4j/core/appender/mom/JmsManager.java     |   2 +-
 .../appender/mom/jeromq/JeroMqAppender.java     | 229 +-------
 .../core/appender/mom/jeromq/JeroMqManager.java | 220 ++++++++
 .../core/appender/mom/kafka/KafkaAppender.java  |  12 +-
 .../core/appender/mom/kafka/KafkaManager.java   |   4 +
 .../rolling/RollingRandomAccessFileManager.java |   2 +-
 .../log4j/core/async/AsyncEventRouter.java      |   7 +-
 .../core/async/AsyncEventRouterFactory.java     |  44 +-
 .../logging/log4j/core/async/AsyncLogger.java   | 165 +++---
 .../log4j/core/async/AsyncLoggerConfig.java     |   6 +-
 .../core/async/AsyncLoggerConfigDelegate.java   |   2 +
 .../core/async/AsyncLoggerConfigDisruptor.java  |  20 +-
 .../log4j/core/async/AsyncLoggerDisruptor.java  |  12 +-
 .../core/async/DefaultAsyncEventRouter.java     |   5 +-
 .../core/async/DiscardingAsyncEventRouter.java  |  35 +-
 .../logging/log4j/core/async/EventRoute.java    |   4 +-
 .../log4j/core/async/RingBufferLogEvent.java    |  27 +-
 .../async/RingBufferLogEventTranslator.java     |  53 +-
 .../core/config/AbstractConfiguration.java      |   1 +
 .../log4j/core/config/ConfigurationAware.java   |  33 ++
 .../log4j/core/config/CronScheduledFuture.java  |  12 +-
 .../logging/log4j/core/config/LoggerConfig.java |  51 +-
 .../builder/api/AppenderComponentBuilder.java   |   9 +-
 .../api/AppenderRefComponentBuilder.java        |   9 +-
 .../api/CompositeFilterComponentBuilder.java    |  14 +-
 .../builder/api/FilterableComponentBuilder.java |  34 ++
 .../builder/api/LoggableComponentBuilder.java   |  33 ++
 .../builder/api/LoggerComponentBuilder.java     |  16 +-
 .../builder/api/RootLoggerComponentBuilder.java |  16 +-
 .../core/config/builder/api/package-info.java   |   2 +
 .../config/builder/impl/BuiltConfiguration.java |  17 +-
 .../impl/DefaultAppenderComponentBuilder.java   |   2 +
 .../DefaultAppenderRefComponentBuilder.java     |   2 +
 ...DefaultComponentAndConfigurationBuilder.java |   2 +
 .../builder/impl/DefaultComponentBuilder.java   |  22 +-
 .../DefaultCompositeFilterComponentBuilder.java |   2 +-
 .../impl/DefaultConfigurationBuilder.java       |  16 +-
 .../DefaultCustomLevelComponentBuilder.java     |   2 +-
 .../impl/DefaultFilterComponentBuilder.java     |   2 +-
 .../impl/DefaultLayoutComponentBuilder.java     |   2 +-
 .../impl/DefaultLoggerComponentBuilder.java     |   4 +-
 .../impl/DefaultRootLoggerComponentBuilder.java |   4 +-
 .../impl/DefaultScriptComponentBuilder.java     |   2 +-
 .../impl/DefaultScriptFileComponentBuilder.java |   2 +
 .../core/config/builder/impl/package-info.java  |   2 +
 .../core/config/json/JsonConfiguration.java     | 550 +++++++++----------
 .../PropertiesConfigurationBuilder.java         | 298 ++++++++++
 .../PropertiesConfigurationFactory.java         | 378 +------------
 .../core/config/status/StatusConfiguration.java |   4 +-
 .../log4j/core/config/xml/XmlConfiguration.java |  14 +-
 .../log4j/core/filter/CompositeFilter.java      |  76 +--
 .../logging/log4j/core/impl/Log4jLogEvent.java  |  16 +-
 .../AbstractConfigurationAwareLookup.java       |  35 ++
 .../logging/log4j/core/lookup/Interpolator.java |   6 +-
 .../logging/log4j/core/lookup/JndiLookup.java   |   5 +-
 .../logging/log4j/core/lookup/Log4jLookup.java  |  60 +-
 .../log4j/core/lookup/StrSubstitutor.java       |  19 +-
 .../logging/log4j/core/net/SmtpManager.java     |  15 +-
 .../log4j/core/net/SslSocketManager.java        |   2 +-
 .../pattern/EqualsReplacementConverter.java     |  48 +-
 .../logging/log4j/core/util/KeyValuePair.java   |   3 -
 .../log4j/core/util/ObjectArrayIterator.java    | 179 ++++++
 .../logging/log4j/core/util/StringEncoder.java  |   2 +-
 .../log4j/core/CustomLevelsWithFiltersTest.java |   8 +-
 .../logging/log4j/core/GcFreeLoggingTest.java   | 131 +++++
 .../logging/log4j/core/LoggerUpdateTest.java    |  15 +
 .../appender/mom/jeromq/JeroMqAppenderTest.java |  12 +-
 .../rolling/RollingAppenderSizeTest.java        |  15 +-
 .../core/async/AsyncEventRouterFactoryTest.java |  57 +-
 .../core/async/DefaultAsyncEventRouterTest.java |  25 +-
 .../async/DiscardingAsyncEventRouterTest.java   |  79 +--
 .../log4j/core/config/ConfigurationTest.java    |   3 +-
 .../core/config/CustomConfigurationTest.java    |   2 +-
 .../log4j/core/layout/PatternLayoutTest.java    |  87 ++-
 .../log4j/core/lookup/JndiLookupTest.java       |  18 +
 .../log4j/core/lookup/Log4jLookupTest.java      |  32 +-
 .../core/lookup/Log4jLookupWithSpacesTest.java  |  16 +-
 .../core/pattern/DatePatternConverterTest.java  |   2 +-
 .../pattern/EqualsReplacementConverterTest.java |  63 ++-
 .../apache/logging/log4j/core/util/Compare.java | 134 -----
 .../log4j/core/util/PropertiesUtilTest.java     |  42 --
 .../apache/logging/log4j/junit/CleanFiles.java  |   2 +-
 .../log4j/test/appender/AlwaysFailAppender.java |  11 +-
 .../log4j/test/appender/DeadlockAppender.java   |  13 +-
 .../log4j/test/appender/FailOnceAppender.java   |  13 +-
 .../log4j/test/appender/InMemoryAppender.java   |   2 -
 .../log4j/test/appender/ListAppender.java       |   6 +-
 .../test/appender/UsesLoggingAppender.java      |  22 +-
 .../src/test/resources/log4j-routing.properties |   9 -
 .../log4j-scriptFile-filters.properties         |   8 -
 .../src/test/resources/log4j-test1.properties   |  58 ++
 .../log4j2-properties-root-only.properties      |   6 -
 .../test/resources/log4j2-properties.properties |   9 -
 .../appender/FlumeEmbeddedAppenderTest.java     |  10 +-
 log4j-jmx-gui/pom.xml                           |   4 +-
 .../log4j/web/Log4jWebInitializerImpl.java      |   5 +-
 .../log4j/web/appender/ServletAppender.java     |   4 +-
 pom.xml                                         |   8 +-
 src/changes/changes.xml                         |  26 +-
 src/site/xdoc/manual/async.xml                  |   8 +-
 src/site/xdoc/manual/configuration.xml.vm       |  52 +-
 133 files changed, 3677 insertions(+), 2060 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7b9077c3/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
----------------------------------------------------------------------
diff --cc log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index 0694973,244b8e7..f21c697
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@@ -26,9 -26,8 +26,9 @@@ import org.apache.logging.log4j.message
  import org.apache.logging.log4j.message.FlowMessageFactory;
  import org.apache.logging.log4j.message.Message;
  import org.apache.logging.log4j.message.MessageFactory;
 +import org.apache.logging.log4j.message.MessageFactory2;
  import org.apache.logging.log4j.message.ParameterizedMessageFactory;
- import org.apache.logging.log4j.message.ReusableParameterizedMessageFactory;
+ import org.apache.logging.log4j.message.ReusableMessageFactory;
  import org.apache.logging.log4j.message.StringFormattedMessage;
  import org.apache.logging.log4j.status.StatusLogger;
  import org.apache.logging.log4j.util.LambdaUtil;


[36/50] logging-log4j2 git commit: LOG4J2-1080 RingBufferLogEventTranslator optimization

Posted by rp...@apache.org.
LOG4J2-1080 RingBufferLogEventTranslator optimization

 - increased visibility of some fields to protected to facilitate falling back to AsyncEventRouter when the queue is full
 - RingBufferLogEventTranslator now initializes thread-related fields when the thread-local instance is constructed
 - thread-related fields are not modified by default
 - a separate method is available for modifying thread-related fields


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 43cefdd8677052230d7ccdfb762526f507225afc
Parents: 32e3069
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 02:08:43 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 02:08:43 2016 +1100

----------------------------------------------------------------------
 .../async/RingBufferLogEventTranslator.java     | 53 ++++++--------------
 1 file changed, 15 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/43cefdd8/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
index 37a4825..da15ed6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
@@ -36,16 +36,16 @@ public class RingBufferLogEventTranslator implements
 
     private AsyncLogger asyncLogger;
     private String loggerName;
-    private Marker marker;
-    private String fqcn;
-    private Level level;
-    private Message message;
-    private Throwable thrown;
+    protected Marker marker;
+    protected String fqcn;
+    protected Level level;
+    protected Message message;
+    protected Throwable thrown;
     private Map<String, String> contextMap;
     private ContextStack contextStack;
-    private long threadId;
-    private String threadName;
-    private int threadPriority;
+    private long threadId = Thread.currentThread().getId();
+    private String threadName = Thread.currentThread().getName();
+    private int threadPriority = Thread.currentThread().getPriority();
     private StackTraceElement location;
     private long currentTimeMillis;
     private long nanoTime;
@@ -59,11 +59,10 @@ public class RingBufferLogEventTranslator implements
     }
 
     /**
-     * Release references held by this object to allow objects to be
-     * garbage-collected.
+     * Release references held by this object to allow objects to be garbage-collected.
      */
     private void clear() {
-        setValues(null, // asyncLogger
+        setBasicValues(null, // asyncLogger
                 null, // loggerName
                 null, // marker
                 null, // fqcn
@@ -72,18 +71,16 @@ public class RingBufferLogEventTranslator implements
                 null, // t
                 null, // map
                 null, // contextStack
-                0, // threadName
                 null, // location
                 0, // currentTimeMillis
-                null, 
-                0, 0 // nanoTime
+                0 // nanoTime
         );
     }
 
-    public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
+    public void setBasicValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
             final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
-            final Map<String, String> aMap, final ContextStack aContextStack, long threadId,
-            final String threadName, int threadPriority, final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) {
+            final Map<String, String> aMap, final ContextStack aContextStack, final StackTraceElement aLocation,
+            final long aCurrentTimeMillis, final long aNanoTime) {
         this.asyncLogger = anAsyncLogger;
         this.loggerName = aLoggerName;
         this.marker = aMarker;
@@ -93,34 +90,14 @@ public class RingBufferLogEventTranslator implements
         this.thrown = aThrowable;
         this.contextMap = aMap;
         this.contextStack = aContextStack;
-        this.threadId = threadId;
-        this.threadName = threadName;
-        this.threadPriority = threadPriority;
         this.location = aLocation;
         this.currentTimeMillis = aCurrentTimeMillis;
         this.nanoTime = aNanoTime;
     }
 
-    public void setValuesPart1(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
-            final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable) {
-        this.asyncLogger = anAsyncLogger;
-        this.loggerName = aLoggerName;
-        this.marker = aMarker;
-        this.fqcn = theFqcn;
-        this.level = aLevel;
-        this.message = msg;
-        this.thrown = aThrowable;
-    }
-
-    public void setValuesPart2(final Map<String, String> aMap, final ContextStack aContextStack, long threadId,
-            final String threadName, int threadPriority, final StackTraceElement aLocation, final long aCurrentTimeMillis, final long aNanoTime) {
-        this.contextMap = aMap;
-        this.contextStack = aContextStack;
+    public void setThreadValues(final long threadId, final String threadName, final int threadPriority) {
         this.threadId = threadId;
         this.threadName = threadName;
         this.threadPriority = threadPriority;
-        this.location = aLocation;
-        this.currentTimeMillis = aCurrentTimeMillis;
-        this.nanoTime = aNanoTime;
     }
 }


[19/50] logging-log4j2 git commit: Remove unused test support class.

Posted by rp...@apache.org.
Remove unused test support class.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 3d4fb63050aab105e3d960f449b4b2f45a5cca3b
Parents: c48bfc5
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Mar 9 10:57:35 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Mar 9 10:57:35 2016 -0600

----------------------------------------------------------------------
 .../apache/logging/log4j/core/util/Compare.java | 134 -------------------
 1 file changed, 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3d4fb630/log4j-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java
deleted file mode 100644
index 57401d1..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.core.util;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-public class Compare {
-    static final int B1_NULL = -1;
-    static final int B2_NULL = -2;
-
-    private static final InputStream open(
-        final Class<?> testClass,
-        final String fileName) throws IOException {
-        final String resourceName = fileName;
-        /* if (fileName.startsWith("witness/")) {
-           resourceName = fileName.substring(fileName.lastIndexOf('/') + 1);
-       } */
-        InputStream is = testClass.getResourceAsStream(resourceName);
-        if (is == null) {
-            is = testClass.getClassLoader().getResourceAsStream(resourceName);
-        }
-        if (is == null) {
-            final File file = new File(fileName);
-            if (file.exists()) {
-                is = new FileInputStream(file);
-            } else {
-                throw new FileNotFoundException("Resource "
-                    + resourceName + " not found");
-            }
-        }
-        return is;
-    }
-
-    public static boolean compare(final Class<?> testClass,
-                                  final String file1,
-                                  final String file2)
-        throws IOException {
-        try (final BufferedReader in1 = new BufferedReader(new FileReader(file1));
-             final BufferedReader in2 = new BufferedReader(new InputStreamReader(open(testClass, file2)))) {
-            return compare(testClass, file1, file2, in1, in2);
-        }
-    }
-
-    public static boolean compare(
-        final Class<?> testClass, final String file1, final String file2, final BufferedReader in1, final BufferedReader in2) throws IOException {
-
-        String s1;
-        int lineCounter = 0;
-
-        while ((s1 = in1.readLine()) != null) {
-            lineCounter++;
-
-            final String s2 = in2.readLine();
-
-            if (!s1.equals(s2)) {
-                System.out.println(
-                    "Files [" + file1 + "] and [" + file2 + "] differ on line "
-                        + lineCounter);
-                System.out.println("One reads:  [" + s1 + "].");
-                System.out.println("Other reads:[" + s2 + "].");
-                outputFile(testClass, file1);
-                outputFile(testClass, file2);
-
-                return false;
-            }
-        }
-
-        // the second file is longer
-        if (in2.read() != -1) {
-            System.out.println(
-                "File [" + file2 + "] longer than file [" + file1 + "].");
-            outputFile(testClass, file1);
-            outputFile(testClass, file2);
-
-            return false;
-        }
-
-        return true;
-    }
-
-    /**
-     * Prints file on the console.
-     */
-    private static void outputFile(final Class<?> testClass, final String file)
-        throws IOException {
-        final InputStream is = open(testClass, file);
-        final BufferedReader in1 = new BufferedReader(new InputStreamReader(is));
-
-        String s1;
-        int lineCounter = 0;
-        System.out.println("--------------------------------");
-        System.out.println("Contents of " + file + ':');
-
-        while ((s1 = in1.readLine()) != null) {
-            lineCounter++;
-            System.out.print(lineCounter);
-
-            if (lineCounter < 10) {
-                System.out.print("   : ");
-            } else if (lineCounter < 100) {
-                System.out.print("  : ");
-            } else if (lineCounter < 1000) {
-                System.out.print(" : ");
-            } else {
-                System.out.print(": ");
-            }
-
-            System.out.println(s1);
-        }
-        in1.close();
-    }
-}


[18/50] logging-log4j2 git commit: Format nit.

Posted by rp...@apache.org.
Format nit.


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: c48bfc5d9ddc93c0026200485e29e877de80e1c5
Parents: 0d2cfbe
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Mar 9 10:56:37 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Mar 9 10:56:37 2016 -0600

----------------------------------------------------------------------
 .../org/apache/logging/log4j/web/appender/ServletAppender.java   | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c48bfc5d/log4j-web/src/main/java/org/apache/logging/log4j/web/appender/ServletAppender.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/appender/ServletAppender.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/appender/ServletAppender.java
index 606e45c..6cfa74e 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/appender/ServletAppender.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/appender/ServletAppender.java
@@ -64,9 +64,7 @@ public class ServletAppender extends AbstractAppender {
     public static ServletAppender createAppender(
             @PluginElement("Layout") Layout<? extends Serializable> layout,
             @PluginElement("Filter") final Filter filter,
-            @PluginAttribute("name")
-            @Required(message = "No name provided for ServletAppender")
-            final String name,
+            @PluginAttribute("name") @Required(message = "No name provided for ServletAppender") final String name,
             @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions) {
         final ServletContext servletContext = WebLoggerContextUtils.getServletContext();
         if (servletContext == null) {


[29/50] logging-log4j2 git commit: LOG4J2-1080 removed support for dropping events on partially full queue, removed support for property "log4j2.DiscardQueueRatio"

Posted by rp...@apache.org.
LOG4J2-1080 removed support for dropping events on partially full queue, removed support for property "log4j2.DiscardQueueRatio"


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 6af9e31d117540ab57fa17b82967dbdff4e95868
Parents: f5a69e8
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:56:55 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:56:55 2016 +1100

----------------------------------------------------------------------
 .../log4j/core/async/AsyncEventRouter.java      |  7 +---
 .../core/async/AsyncEventRouterFactory.java     | 44 +++++++-------------
 .../core/async/DefaultAsyncEventRouter.java     |  5 +--
 .../core/async/DiscardingAsyncEventRouter.java  | 35 ++++------------
 4 files changed, 26 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
index f2e709a..77ff5d7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
@@ -21,7 +21,7 @@ import org.apache.logging.log4j.Level;
 /**
  * Routing rule for deciding whether to log an event on the current thread, the background thread, or not at all.
  *
- * @since 2.5.1
+ * @since 2.6
  */
 public interface AsyncEventRouter {
 
@@ -30,10 +30,7 @@ public interface AsyncEventRouter {
      *
      * @param backgroundThreadId the thread ID of the background thread. Can be compared with the current thread's ID.
      * @param level the level of the log event
-     * @param queueSize total capacity of the queue used for asynchronous logging
-     * @param queueRemainingCapacity remaining capacity of the queue
      * @return the appropriate route for this routing rule
      */
-    EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
-            final int queueRemainingCapacity);
+    EventRoute getRoute(final long backgroundThreadId, final Level level);
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
index a1b254f..d4f0d8a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
@@ -33,23 +33,21 @@ import org.apache.logging.log4j.util.PropertiesUtil;
  * value {@code "Default"}, this factory creates {@link DefaultAsyncEventRouter} objects.
  * </p> <p>
  * If this property has value {@code "Discard"}, this factory creates {@link DiscardingAsyncEventRouter} objects.
- * By default, this router discards events of level {@code INFO}, {@code DEBUG} and {@code TRACE} if the queue is at
- * 80% capacity or more. This can be adjusted with properties {@code "log4j2.DiscardQueueRatio"} (must be a float
- * between 0.0 and 1.0) and {@code "log4j2.DiscardThreshold"} (name of the level at which to start discarding).
+ * By default, this router discards events of level {@code INFO}, {@code DEBUG} and {@code TRACE} if the queue is full.
+ * This can be adjusted with property {@code "log4j2.DiscardThreshold"} (name of the level at which to start
+ * discarding).
  * </p> <p>
  * For any other value, this
  * factory interprets the value as the fully qualified name of a class implementing the {@link AsyncEventRouter}
- * interface. If a constructor with a single {@code int} argument exists, this constructor is invoked with the queue
- * size, otherwise the default constructor is called.
+ * interface. The class must have a default constructor.
  * </p>
  *
- * @since 2.5.1
+ * @since 2.6
  */
 public class AsyncEventRouterFactory {
     static final String PROPERTY_NAME_ASYNC_EVENT_ROUTER = "log4j2.AsyncEventRouter";
     static final String PROPERTY_VALUE_DEFAULT_ASYNC_EVENT_ROUTER = "Default";
     static final String PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER = "Discard";
-    static final String PROPERTY_NAME_DISCARDING_QUEUE_RATIO = "log4j2.DiscardQueueRatio";
     static final String PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL = "log4j2.DiscardThreshold";
 
     private static final Logger LOGGER = StatusLogger.getLogger();
@@ -63,14 +61,12 @@ public class AsyncEventRouterFactory {
      * If this property has value {@code "Discard"}, this method returns {@link DiscardingAsyncEventRouter} objects.
      * </p> <p>
      * For any other value, this method interprets the value as the fully qualified name of a class implementing the
-     * {@link AsyncEventRouter} interface. If a constructor with a single {@code int} argument exists, this constructor
-     * is invoked with the queue size, otherwise the default constructor is called.
+     * {@link AsyncEventRouter} interface. The class must have a default constructor.
      * </p>
      *
-     * @param queueSize the queue size
      * @return a new AsyncEventRouter
      */
-    public static AsyncEventRouter create(final int queueSize) {
+    public static AsyncEventRouter create() {
         final String router = PropertiesUtil.getProperties().getStringProperty(PROPERTY_NAME_ASYNC_EVENT_ROUTER);
         if (router == null || PROPERTY_VALUE_DEFAULT_ASYNC_EVENT_ROUTER.equals(router)
                 || DefaultAsyncEventRouter.class.getSimpleName().equals(router)
@@ -80,24 +76,16 @@ public class AsyncEventRouterFactory {
         if (PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER.equals(router)
                 || DiscardingAsyncEventRouter.class.getSimpleName().equals(router)
                 || DiscardingAsyncEventRouter.class.getName().equals(router)) {
-            return createDiscardingAsyncEventRouter(queueSize);
+            return createDiscardingAsyncEventRouter();
         }
-        return createCustomRouter(router, queueSize);
+        return createCustomRouter(router);
     }
 
-    private static AsyncEventRouter createCustomRouter(final String router, final int queueSize) {
+    private static AsyncEventRouter createCustomRouter(final String router) {
         try {
             final Class<? extends AsyncEventRouter> cls = LoaderUtil.loadClass(router).asSubclass(AsyncEventRouter.class);
-            try {
-                // if the custom router has a constructor taking an int, pass it the queue size
-                Constructor<? extends AsyncEventRouter> constructor = cls.getDeclaredConstructor(new Class[]{int.class});
-                LOGGER.debug("Creating custom AsyncEventRouter '{}({})'", router, queueSize);
-                return constructor.newInstance(new Object[]{queueSize});
-            } catch (final Exception e) {
-                // otherwise we try the default constructor
-                LOGGER.debug("Creating custom AsyncEventRouter '{}'", router);
-                return cls.newInstance();
-            }
+            LOGGER.debug("Creating custom AsyncEventRouter '{}'", router);
+            return cls.newInstance();
         } catch (final Exception ex) {
             LOGGER.debug("Using DefaultAsyncEventRouter. Could not create custom AsyncEventRouter '{}': {}", router,
                     ex.toString());
@@ -105,13 +93,11 @@ public class AsyncEventRouterFactory {
         }
     }
 
-    private static AsyncEventRouter createDiscardingAsyncEventRouter(final int queueSize) {
+    private static AsyncEventRouter createDiscardingAsyncEventRouter() {
         final PropertiesUtil util = PropertiesUtil.getProperties();
-        final float ratio = (float) util.getDoubleProperty(PROPERTY_NAME_DISCARDING_QUEUE_RATIO, 0.8);
         final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name());
         final Level thresholdLevel = Level.toLevel(level, Level.INFO);
-        LOGGER.debug("Creating custom DiscardingAsyncEventRouter(discardThreshold:{}, discardRatio:{})", thresholdLevel,
-                ratio);
-        return new DiscardingAsyncEventRouter(queueSize, ratio, thresholdLevel);
+        LOGGER.debug("Creating custom DiscardingAsyncEventRouter(discardThreshold:{})", thresholdLevel);
+        return new DiscardingAsyncEventRouter(thresholdLevel);
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
index aee9336..122c4e8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
@@ -25,12 +25,11 @@ import org.apache.logging.log4j.Level;
  */
 public class DefaultAsyncEventRouter implements AsyncEventRouter {
     @Override
-    public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
-            final int queueRemainingCapacity) {
+    public EventRoute getRoute(final long backgroundThreadId, final Level level) {
 
         // LOG4J2-471: prevent deadlock when RingBuffer is full and object
         // being logged calls Logger.log() from its toString() method
-        if (queueRemainingCapacity == 0 && Thread.currentThread().getId() == backgroundThreadId) {
+        if (Thread.currentThread().getId() == backgroundThreadId) {
             return EventRoute.SYNCHRONOUS;
         }
         return EventRoute.ENQUEUE;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
index 2f5805a..8aa3f12 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
@@ -32,48 +32,31 @@ import java.util.concurrent.atomic.AtomicLong;
 public class DiscardingAsyncEventRouter extends DefaultAsyncEventRouter {
     private static final Logger LOGGER = StatusLogger.getLogger();
 
-    private final int thresholdQueueRemainingCapacity;
     private final Level thresholdLevel;
     private final AtomicLong discardCount = new AtomicLong();
 
     /**
      * Constructs a router that will discard events {@linkplain Level#isLessSpecificThan(Level) equal or less specific}
-     * than the specified threshold level when the queue is fuller than the specified threshold ratio.
+     * than the specified threshold level when the queue is full.
      *
-     * @param queueSize size of the queue
-     * @param thresholdQueueFilledRatio threshold ratio: if queue is fuller than this, start discarding events
      * @param thresholdLevel level of events to discard
      */
-    public DiscardingAsyncEventRouter(final int queueSize, final float thresholdQueueFilledRatio,
-            final Level thresholdLevel) {
-        thresholdQueueRemainingCapacity = calcThresholdQueueRemainingCapacity(queueSize, thresholdQueueFilledRatio);
+    public DiscardingAsyncEventRouter(final Level thresholdLevel) {
         this.thresholdLevel = Objects.requireNonNull(thresholdLevel, "thresholdLevel");
     }
 
-    private static int calcThresholdQueueRemainingCapacity(final int queueSize,
-            final float thresholdQueueFilledRatio) {
-        if (thresholdQueueFilledRatio >= 1F) {
-            return 0;
-        }
-        if (thresholdQueueFilledRatio <= 0F) {
-            return queueSize;
-        }
-        return (int) ((1 - thresholdQueueFilledRatio) * queueSize);
-    }
-
     @Override
-    public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
-            final int queueRemainingCapacity) {
-        if (queueRemainingCapacity <= thresholdQueueRemainingCapacity && level.isLessSpecificThan(thresholdLevel)) {
+    public EventRoute getRoute(final long backgroundThreadId, final Level level) {
+        if (level.isLessSpecificThan(thresholdLevel)) {
             if (discardCount.getAndIncrement() == 0) {
-                LOGGER.warn("Async remaining queue capacity is {}, discarding event with level {}. " +
+                LOGGER.warn("Async queue is full, discarding event with level {}. " +
                         "This message will only appear once; future events from {} " +
                         "are silently discarded until queue capacity becomes available.",
-                        queueRemainingCapacity, level, thresholdLevel);
+                        level, thresholdLevel);
             }
             return EventRoute.DISCARD;
         }
-        return super.getRoute(backgroundThreadId, level, queueSize, queueRemainingCapacity);
+        return super.getRoute(backgroundThreadId, level);
     }
 
     public static long getDiscardCount(final AsyncEventRouter router) {
@@ -83,10 +66,6 @@ public class DiscardingAsyncEventRouter extends DefaultAsyncEventRouter {
         return 0;
     }
 
-    public int getThresholdQueueRemainingCapacity() {
-        return thresholdQueueRemainingCapacity;
-    }
-
     public Level getThresholdLevel() {
         return thresholdLevel;
     }


[15/50] logging-log4j2 git commit: [LOG4J2-63] Support configuration from version 1.x log4j.properties. Partial support for XML and HTML layouts (defaults only).

Posted by rp...@apache.org.
[LOG4J2-63] Support configuration from version 1.x log4j.properties.
Partial support for XML and HTML layouts (defaults only).

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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 1ecb8ec81d75a4dedf6dada396af1699bb169d58
Parents: 9a01ec6
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 9 00:42:41 2016 -0800
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 9 00:42:41 2016 -0800

----------------------------------------------------------------------
 log4j-1.2-api/pom.xml                           |  5 ++++
 .../config/Log4j1ConfigurationFactory.java      | 20 +++++++++-----
 .../config/Log4j1ConfigurationFactoryTest.java  | 28 +++++++++++++++-----
 .../log4j-console-HtmlLayout.properties         | 18 +++++++++++++
 .../log4j-console-XmlLayout.properties          | 18 +++++++++++++
 5 files changed, 77 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ecb8ec8/log4j-1.2-api/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/pom.xml b/log4j-1.2-api/pom.xml
index b5d8814..7fea76d 100644
--- a/log4j-1.2-api/pom.xml
+++ b/log4j-1.2-api/pom.xml
@@ -80,6 +80,11 @@
       <artifactId>commons-io</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.dataformat</groupId>
+      <artifactId>jackson-dataformat-xml</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ecb8ec8/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index 470a3fe..0e5d8d6 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -54,6 +54,8 @@ import org.apache.logging.log4j.status.StatusLogger;
  * <li>Target</li>
  * <li>layout = org.apache.log4j.PatternLayout</li>
  * <li>layout = org.apache.log4j.SimpleLayout</li>
+ * <li>layout = org.apache.log4j.HtmlLayout (partial)</li>
+ * <li>layout = org.apache.log4j.XmlLayout (partial)</li>
  * <li>layout.ConversionPattern</li>
  * </ul>
  * </ul>
@@ -94,25 +96,31 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
             final ConfigurationBuilder<BuiltConfiguration> builder) {
         final AppenderComponentBuilder appenderBuilder = builder.newAppender(name, "CONSOLE");
         buildConsoleAppenderTarget(properties, name, builder, appenderBuilder);
-        buildConsoleAppenderLayout(properties, name, builder, appenderBuilder);
+        buildAppenderLayout(properties, name, builder, appenderBuilder);
         buildConsoleAppenderFollow(properties, name, builder, appenderBuilder);
         builder.add(appenderBuilder);
     }
 
-    private void buildConsoleAppenderLayout(final Properties properties, final String name,
+    private void buildAppenderLayout(final Properties properties, final String name,
             final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
         final String layoutValue = getLog4jAppenderValue(properties, name, "layout", null);
         if (layoutValue != null) {
             final String cpValue = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null);
             switch (layoutValue) {
             case "org.apache.log4j.PatternLayout": {
-                final LayoutComponentBuilder layoutBuilder = newPatternLayout(builder, cpValue);
-                appenderBuilder.add(layoutBuilder);
+                appenderBuilder.add(newPatternLayout(builder, cpValue));
                 break;
             }
             case "org.apache.log4j.SimpleLayout": {
-                final LayoutComponentBuilder layoutBuilder = newPatternLayout(builder, "%level - %m%n");
-                appenderBuilder.add(layoutBuilder);
+                appenderBuilder.add(newPatternLayout(builder, "%level - %m%n"));
+                break;
+            }
+            case "org.apache.log4j.HTMLLayout": {
+                appenderBuilder.add(builder.newLayout("HtmlLayout"));
+                break;
+            }
+            case "org.apache.log4j.XMLLayout": {
+                appenderBuilder.add(builder.newLayout("XmlLayout"));
                 break;
             }
             default:

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ecb8ec8/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 13bcdc2..c31fe37 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -19,17 +19,20 @@ package org.apache.log4j.config;
 import java.net.URL;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.layout.HtmlLayout;
 import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.core.layout.XmlLayout;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class Log4j1ConfigurationFactoryTest {
 
-    private void testConsole(final String configResource, final String expectedPattern) throws Exception {
+    private Layout<?> testConsole(final String configResource) throws Exception {
         final URL configLocation = ClassLoader.getSystemResource(configResource);
         Assert.assertNotNull(configLocation);
         final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration("test",
@@ -38,23 +41,36 @@ public class Log4j1ConfigurationFactoryTest {
         final ConsoleAppender appender = configuration.getAppender("Console");
         Assert.assertNotNull(appender);
         // Can't set ImmediateFlush for a Console Appender in Log4j 2 like you can in 1.2
-        Assert.assertTrue(appender.getImmediateFlush());        
+        Assert.assertTrue(appender.getImmediateFlush());
         Assert.assertEquals(Target.SYSTEM_ERR, appender.getTarget());
-        final PatternLayout layout = (PatternLayout) appender.getLayout();
-        Assert.assertEquals(expectedPattern, layout.getConversionPattern());
         //
         final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
         Assert.assertNotNull(loggerConfig);
         Assert.assertEquals(Level.DEBUG, loggerConfig.getLevel());
+        return appender.getLayout();
+    }
+
+    @Test
+    public void testConsoleHtmlLayout() throws Exception {
+        final Layout<?> layout = testConsole("config-1.2/log4j-console-HtmlLayout.properties");
+        Assert.assertTrue(layout instanceof HtmlLayout);
     }
 
     @Test
     public void testConsolePatternLayout() throws Exception {
-        testConsole("config-1.2/log4j-console-PatternLayout.properties", "%d{ISO8601} [%t][%c] %-5p: %m%n");
+        final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-PatternLayout.properties");
+        Assert.assertEquals("%d{ISO8601} [%t][%c] %-5p: %m%n", layout.getConversionPattern());
     }
 
     @Test
     public void testConsoleSimpleLayout() throws Exception {
-        testConsole("config-1.2/log4j-console-SimpleLayout.properties", "%level - %m%n");
+        final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-SimpleLayout.properties");
+        Assert.assertEquals("%level - %m%n", layout.getConversionPattern());
+    }
+
+    @Test
+    public void testConsoleXmlLayout() throws Exception {
+        final Layout<?> layout = testConsole("config-1.2/log4j-console-XmlLayout.properties");
+        Assert.assertTrue(layout instanceof XmlLayout);
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ecb8ec8/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
new file mode 100644
index 0000000..decd369
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
@@ -0,0 +1,18 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.HTMLLayout
+
+log4j.logger.com.example.foo = DEBUG

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ecb8ec8/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
new file mode 100644
index 0000000..155b1ff
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
@@ -0,0 +1,18 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, Console
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.ImmediateFlush=false
+log4j.appender.Console.Target=System.err
+log4j.appender.Console.layout=org.apache.log4j.XMLLayout
+
+log4j.logger.com.example.foo = DEBUG