You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/18 13:37:47 UTC

[01/50] logging-log4j2 git commit: LOG4J2-1334 simplify AsyncAppender: now that any LogEvent can be serialized there is no more need to downcast to Log4jLogEvent or copy a RingBufferLogEvent into a Log4jLogEvent

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1365 299f488dc -> 86934ca41


LOG4J2-1334 simplify AsyncAppender: now that any LogEvent can be serialized there is no more need to downcast to Log4jLogEvent or copy a RingBufferLogEvent into a Log4jLogEvent


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

Branch: refs/heads/LOG4J2-1365
Commit: 08228f2da38ae1afac22e0681dff3a5a1d944a4c
Parents: 412d794
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 14:30:56 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 14:30:56 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/appender/AsyncAppender.java      | 28 +++++---------------
 .../logging/log4j/core/async/EventRoute.java    |  9 +++----
 2 files changed, 11 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/08228f2d/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 31bdfbf..aa10155 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
@@ -24,7 +24,6 @@ import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.LogEvent;
@@ -32,7 +31,6 @@ import org.apache.logging.log4j.core.async.AsyncEventRouter;
 import org.apache.logging.log4j.core.async.AsyncEventRouterFactory;
 import org.apache.logging.log4j.core.async.DiscardingAsyncEventRouter;
 import org.apache.logging.log4j.core.async.EventRoute;
-import org.apache.logging.log4j.core.async.RingBufferLogEvent;
 import org.apache.logging.log4j.core.config.AppenderControl;
 import org.apache.logging.log4j.core.config.AppenderRef;
 import org.apache.logging.log4j.core.config.Configuration;
@@ -145,22 +143,10 @@ public final class AsyncAppender extends AbstractAppender {
         if (!isStarted()) {
             throw new IllegalStateException("AsyncAppender " + getName() + " is not active");
         }
-        if (!(logEvent instanceof Log4jLogEvent)) {
-            if (!(logEvent instanceof RingBufferLogEvent)) {
-                return; // only know how to Serialize Log4jLogEvents and RingBufferLogEvents
-            }
-            logEvent = ((RingBufferLogEvent) logEvent).createMemento();
-        }
         if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND) { // LOG4J2-898: user may choose
             logEvent.getMessage().getFormattedMessage(); // LOG4J2-763: ask message to freeze parameters
         }
-        final Log4jLogEvent coreEvent = (Log4jLogEvent) logEvent;
-        logEvent(coreEvent);
-    }
-
-    private void logEvent(final Log4jLogEvent logEvent) {
-        final Level logLevel = logEvent.getLevel();
-        final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logLevel);
+        final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logEvent.getLevel());
         route.logMessage(this, logEvent);
     }
 
@@ -169,7 +155,7 @@ public final class AsyncAppender extends AbstractAppender {
      *
      * @param logEvent the event to log
      */
-    public void logMessageInCurrentThread(final Log4jLogEvent logEvent) {
+    public void logMessageInCurrentThread(final LogEvent logEvent) {
         logEvent.setEndOfBatch(queue.isEmpty());
         final boolean appendSuccessful = thread.callAppenders(logEvent);
         logToErrorAppenderIfNecessary(appendSuccessful, logEvent);
@@ -180,12 +166,12 @@ public final class AsyncAppender extends AbstractAppender {
      *
      * @param logEvent the event to log
      */
-    public void logMessageInBackgroundThread(final Log4jLogEvent logEvent) {
+    public void logMessageInBackgroundThread(final LogEvent logEvent) {
         final boolean success = blocking ? enqueueOrBlockIfQueueFull(logEvent) : enqueueOrDropIfQueueFull(logEvent);
         logToErrorAppenderIfNecessary(success, logEvent);
     }
 
-    private boolean enqueueOrBlockIfQueueFull(final Log4jLogEvent logEvent) {
+    private boolean enqueueOrBlockIfQueueFull(final LogEvent logEvent) {
         boolean appendSuccessful;
         final Serializable serialized = Log4jLogEvent.serialize(logEvent, includeLocation);
         try {
@@ -198,7 +184,7 @@ public final class AsyncAppender extends AbstractAppender {
         return appendSuccessful;
     }
 
-    private boolean enqueueOrDropIfQueueFull(final Log4jLogEvent logEvent) {
+    private boolean enqueueOrDropIfQueueFull(final LogEvent logEvent) {
         final boolean appendSuccessful = queue.offer(Log4jLogEvent.serialize(logEvent, includeLocation));
         if (!appendSuccessful) {
             error("Appender " + getName() + " is unable to write primary appenders. queue is full");
@@ -228,7 +214,7 @@ public final class AsyncAppender extends AbstractAppender {
         return appendSuccessful;
     }
 
-    private void logToErrorAppenderIfNecessary(final boolean appendSuccessful, final Log4jLogEvent logEvent) {
+    private void logToErrorAppenderIfNecessary(final boolean appendSuccessful, final LogEvent logEvent) {
         if (!appendSuccessful && errorAppender != null) {
             errorAppender.callAppender(logEvent);
         }
@@ -350,7 +336,7 @@ public final class AsyncAppender extends AbstractAppender {
          * @param event the event to forward to the registered appenders
          * @return {@code true} if at least one appender call succeeded, {@code false} otherwise
          */
-        boolean callAppenders(final Log4jLogEvent event) {
+        boolean callAppenders(final LogEvent event) {
             boolean success = false;
             for (final AppenderControl control : appenders) {
                 try {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/08228f2d/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 ce57008..2558010 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
@@ -20,7 +20,6 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.AsyncAppender;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.message.Message;
 
 /**
@@ -44,7 +43,7 @@ public enum EventRoute {
         }
 
         @Override
-        public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent logEvent) {
+        public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
             asyncAppender.logMessageInBackgroundThread(logEvent);
         }
     },
@@ -63,7 +62,7 @@ public enum EventRoute {
         }
 
         @Override
-        public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent logEvent) {
+        public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
             asyncAppender.logMessageInCurrentThread(logEvent);
         }
     },
@@ -83,7 +82,7 @@ public enum EventRoute {
         }
 
         @Override
-        public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent coreEvent) {
+        public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) {
             // do nothing: drop the event
         }
     };
@@ -93,5 +92,5 @@ public enum EventRoute {
 
     public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event);
 
-    public abstract void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent coreEvent);
+    public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent);
 }


[18/50] logging-log4j2 git commit: LOG4J2-1334 javadoc

Posted by mi...@apache.org.
LOG4J2-1334 javadoc


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

Branch: refs/heads/LOG4J2-1365
Commit: aa4ce1ef171b733f6866ebffa7782eadbe16a370
Parents: 5540868
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 15:49:51 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 15:49:51 2016 +0900

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/impl/MutableLogEvent.java  | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/aa4ce1ef/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index e86c553..9ca179b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -70,6 +70,9 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         setMessage(event.getMessage());
     }
 
+    /**
+     * Clears all references this event has to other objects.
+     */
     public void clear() {
         loggerFqcn = null;
         marker = null;


[33/50] logging-log4j2 git commit: Use Java 7 diamonds.

Posted by mi...@apache.org.
Use Java 7 diamonds.

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

Branch: refs/heads/LOG4J2-1365
Commit: f275612d595642c9a95c2e8a313cf17741b3e2de
Parents: 661e117
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:39:02 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:39:02 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/perf/jmh/CollectionsBenchmark.java    | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f275612d/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/CollectionsBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/CollectionsBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/CollectionsBenchmark.java
index 37fa593..ea40dac 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/CollectionsBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/CollectionsBenchmark.java
@@ -39,12 +39,12 @@ import org.openjdk.jmh.infra.Blackhole;
 //
 @State(Scope.Benchmark)
 public class CollectionsBenchmark {
-    private final ConcurrentHashMap<String, Long> map1 = new ConcurrentHashMap<String, Long>();
-    private final CopyOnWriteArraySet<Long> arraySet1 = new CopyOnWriteArraySet<Long>();
-    private final CopyOnWriteArrayList<Long> arrayList1 = new CopyOnWriteArrayList<Long>();
-    private final ConcurrentHashMap<String, Long> map3 = new ConcurrentHashMap<String, Long>();
-    private final CopyOnWriteArraySet<Long> arraySet3 = new CopyOnWriteArraySet<Long>();
-    private final CopyOnWriteArrayList<Long> arrayList3 = new CopyOnWriteArrayList<Long>();
+    private final ConcurrentHashMap<String, Long> map1 = new ConcurrentHashMap<>();
+    private final CopyOnWriteArraySet<Long> arraySet1 = new CopyOnWriteArraySet<>();
+    private final CopyOnWriteArrayList<Long> arrayList1 = new CopyOnWriteArrayList<>();
+    private final ConcurrentHashMap<String, Long> map3 = new ConcurrentHashMap<>();
+    private final CopyOnWriteArraySet<Long> arraySet3 = new CopyOnWriteArraySet<>();
+    private final CopyOnWriteArrayList<Long> arrayList3 = new CopyOnWriteArrayList<>();
 
     @Setup
     public void setup() {


[48/50] logging-log4j2 git commit: Do not use our own deprecated code.

Posted by mi...@apache.org.
Do not use our own deprecated code.

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

Branch: refs/heads/LOG4J2-1365
Commit: d3e571f37bd9a2ef07e426a1809d3cb1f69c3482
Parents: a15477b
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:26:34 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:26:34 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/AppenderRefLevelJsonTest.java   | 12 ++++++------
 .../logging/log4j/core/AppenderRefLevelTest.java       | 12 ++++++------
 .../apache/logging/log4j/core/PatternSelectorTest.java | 12 ++++++------
 .../apache/logging/log4j/core/StrictXmlConfigTest.java | 13 +++++++++++--
 .../log4j/core/filter/AbstractScriptFilterTest.java    |  4 ++--
 5 files changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
index a6c7697..3d9424a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
@@ -52,36 +52,36 @@ public class AppenderRefLevelJsonTest {
 
     @Test
     public void logger1() {
-        logger1.entry();
+        logger1.traceEntry();
         logger1.debug("debug message");
         logger1.error("Test Message");
         logger1.info("Info Message");
         logger1.warn("warn Message");
-        logger1.exit();
+        logger1.traceExit();
         assertThat(app1.getEvents(), hasSize(6));
         assertThat(app2.getEvents(), hasSize(1));
     }
 
     @Test
     public void logger2() {
-        logger2.entry();
+        logger2.traceEntry();
         logger2.debug("debug message");
         logger2.error("Test Message");
         logger2.info("Info Message");
         logger2.warn("warn Message");
-        logger2.exit();
+        logger2.traceExit();
         assertThat(app1.getEvents(), hasSize(2));
         assertThat(app2.getEvents(), hasSize(4));
     }
 
     @Test
     public void logger3() {
-        logger3.entry();
+        logger3.traceEntry();
         logger3.debug(testMarker, "debug message");
         logger3.error("Test Message");
         logger3.info(testMarker, "Info Message");
         logger3.warn("warn Message");
-        logger3.exit();
+        logger3.traceExit();
         assertThat(app1.getEvents(), hasSize(4));
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
index d59c1a0..861ed87 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
@@ -53,12 +53,12 @@ public class AppenderRefLevelTest {
 
     @Test
     public void logger1() {
-        logger1.entry();
+        logger1.traceEntry();
         logger1.debug("debug message");
         logger1.error("Test Message");
         logger1.info("Info Message");
         logger1.warn("warn Message");
-        logger1.exit();
+        logger1.traceExit();
         List<LogEvent> events = app1.getEvents();
         assertEquals("Incorrect number of events. Expected 6, actual " + events.size(), 6, events.size());
         events = app2.getEvents();
@@ -67,12 +67,12 @@ public class AppenderRefLevelTest {
 
     @Test
     public void logger2() {
-        logger2.entry();
+        logger2.traceEntry();
         logger2.debug("debug message");
         logger2.error("Test Message");
         logger2.info("Info Message");
         logger2.warn("warn Message");
-        logger2.exit();
+        logger2.traceExit();
         List<LogEvent> events = app1.getEvents();
         assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), events.size(), 2);
         events = app2.getEvents();
@@ -81,12 +81,12 @@ public class AppenderRefLevelTest {
 
     @Test
     public void logger3() {
-        logger3.entry();
+        logger3.traceEntry();
         logger3.debug(testMarker, "debug message");
         logger3.error("Test Message");
         logger3.info(testMarker, "Info Message");
         logger3.warn("warn Message");
-        logger3.exit();
+        logger3.traceExit();
         final List<LogEvent> events = app1.getEvents();
         assertEquals("Incorrect number of events. Expected 4, actual " + events.size(), 4, events.size());
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
index 9fda787..1214e4e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
@@ -40,9 +40,9 @@ public class PatternSelectorTest {
     @Test
     public void testMarkerPatternSelector() throws Exception {
         org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestMarkerPatternSelector");
-        logger.entry();
+        logger.traceEntry();
         logger.info("Hello World");
-        logger.exit();
+        logger.traceExit();
         final ListAppender app = (ListAppender) context.getRequiredAppender("List");
         assertNotNull("No ListAppender", app);
         List<String> messages = app.getMessages();
@@ -59,10 +59,10 @@ public class PatternSelectorTest {
     public void testScriptPatternSelector() throws Exception {
         org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector");
         org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation");
-        logger.entry();
+        logger.traceEntry();
         logger.info("Hello World");
         logger2.info("No location information");
-        logger.exit();
+        logger.traceExit();
         final ListAppender app = (ListAppender) context.getRequiredAppender("List2");
         assertNotNull("No ListAppender", app);
         List<String> messages = app.getMessages();
@@ -82,10 +82,10 @@ public class PatternSelectorTest {
     public void testJavaScriptPatternSelector() throws Exception {
         org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestJavaScriptPatternSelector");
         org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("JavascriptNoLocation");
-        logger.entry();
+        logger.traceEntry();
         logger.info("Hello World");
         logger2.info("No location information");
-        logger.exit();
+        logger.traceExit();
         final ListAppender app = (ListAppender) context.getRequiredAppender("List3");
         assertNotNull("No ListAppender", app);
         List<String> messages = app.getMessages();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
index edc428e..f94a60d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
@@ -23,6 +23,7 @@ import java.util.Locale;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.EntryMessage;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.Before;
@@ -51,8 +52,16 @@ public class StrictXmlConfigTest {
 
     @Test
     public void basicFlow() {
-        logger.entry();
-        logger.exit();
+        final EntryMessage entry = logger.traceEntry();
+        logger.traceExit(entry);
+        final List<LogEvent> events = app.getEvents();
+        assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
+    }
+
+    @Test
+    public void basicFlowDeprecated() {
+        logger.traceEntry();
+        logger.traceExit();
         final List<LogEvent> events = app.getEvents();
         assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
index 56fa8f4..a2e949c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
@@ -38,7 +38,7 @@ public abstract class AbstractScriptFilterTest {
     @Test
     public void testGroovyFilter() throws Exception {
         Logger logger = LogManager.getLogger("TestGroovyFilter");
-        logger.entry();
+        logger.traceEntry();
         logger.info("This should not be logged");
         ThreadContext.put("UserId", "JohnDoe");
         logger.info("This should be logged");
@@ -56,7 +56,7 @@ public abstract class AbstractScriptFilterTest {
     @Test
     public void testJavascriptFilter() throws Exception {
         Logger logger = LogManager.getLogger("TestJavaScriptFilter");
-        logger.entry();
+        logger.traceEntry();
         logger.info("This should not be logged");
         ThreadContext.put("UserId", "JohnDoe");
         logger.info("This should be logged");


[36/50] logging-log4j2 git commit: Add traceEntry/Exit() tests.

Posted by mi...@apache.org.
Add traceEntry/Exit() tests.

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

Branch: refs/heads/LOG4J2-1365
Commit: 8f1e0b23dfcf39ff48b64041103d0b403d711ba3
Parents: b285279
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:45:12 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:45:12 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/slf4j/LoggerTest.java    | 360 ++++++++++---------
 1 file changed, 187 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8f1e0b23/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index c061782..77b9c4e 100644
--- a/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-to-slf4j/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -1,173 +1,187 @@
-
-/*
-* 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.slf4j;
-
-import java.util.Date;
-import java.util.List;
-
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.testUtil.StringListAppender;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.message.MessageFactory;
-import org.apache.logging.log4j.message.ParameterizedMessageFactory;
-import org.apache.logging.log4j.message.StringFormatterMessageFactory;
-import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.spi.MessageFactory2Adapter;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class LoggerTest {
-
-    private static final String CONFIG = "target/test-classes/logback-slf4j.xml";
-
-    @ClassRule
-    public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG);
-
-    private Logger logger;
-    private StringListAppender<ILoggingEvent> list;
-
-    @Before
-    public void setUp() throws Exception {
-        final org.slf4j.Logger slf4jLogger = CTX.getLogger();
-        logger = LogManager.getLogger();
-        assertThat(slf4jLogger, is(theInstance(((SLF4JLogger) logger).getLogger())));
-        final ch.qos.logback.classic.Logger rootLogger = CTX.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
-        rootLogger.detachAppender("console");
-        list = TestUtil.getListAppender(rootLogger, "LIST");
-        assertThat(list, is(notNullValue()));
-        assertThat(list.strList, is(notNullValue()));
-        list.strList.clear();
-    }
-
-    @Test
-    public void basicFlow() {
-        logger.entry();
-        logger.exit();
-        assertThat(list.strList, hasSize(2));
-    }
-
-    @Test
-    public void simpleFlow() {
-        logger.entry(CONFIG);
-        logger.exit(0);
-        assertThat(list.strList, hasSize(2));
-    }
-
-    @Test
-    public void throwing() {
-        logger.throwing(new IllegalArgumentException("Test Exception"));
-        assertThat(list.strList, hasSize(1));
-    }
-
-    @Test
-    public void catching() {
-        try {
-            throw new NullPointerException();
-        } catch (final Exception e) {
-            logger.catching(e);
-        }
-        assertThat(list.strList, hasSize(1));
-    }
-
-    @Test
-    public void debug() {
-        logger.debug("Debug message");
-        assertThat(list.strList, hasSize(1));
-    }
-
-    @Test
-    public void getLogger_String_MessageFactoryMismatch() {
-        final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
-            StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
-        testLogger.debug("%,d", Integer.MAX_VALUE);
-        assertThat(list.strList, hasSize(1));
-        assertThat(list.strList, hasItem(String.format("%,d", Integer.MAX_VALUE)));
-    }
-
-    @Test
-    public void getLogger_String_MessageFactoryMismatchNull() {
-        final Logger testLogger =  testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatchNull",
-            StringFormatterMessageFactory.INSTANCE, null);
-        testLogger.debug("%,d", Integer.MAX_VALUE);
-        assertThat(list.strList, hasSize(1));
-        assertThat(list.strList, hasItem(String.format("%,d", Integer.MAX_VALUE)));
-    }
-
-    private Logger testMessageFactoryMismatch(final String name, final MessageFactory messageFactory1, final MessageFactory messageFactory2) {
-        final Logger testLogger = LogManager.getLogger(name, messageFactory1);
-        assertThat(testLogger, is(notNullValue()));
-        checkMessageFactory(messageFactory1, testLogger);
-        final Logger testLogger2 = LogManager.getLogger(name, messageFactory2);
-        checkMessageFactory(messageFactory1, testLogger2);
-        return testLogger;
-    }
-
-    private static void checkMessageFactory(final MessageFactory messageFactory1, final Logger testLogger1) {
-        if (messageFactory1 == null) {
-            assertEquals(AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, testLogger1.getMessageFactory().getClass());
-        } else {
-            MessageFactory actual = testLogger1.getMessageFactory();
-            if (actual instanceof MessageFactory2Adapter) {
-                actual = ((MessageFactory2Adapter) actual).getOriginal();
-            }
-            assertEquals(messageFactory1, actual);
-        }
-    }
-
-    @Test
-    public void debugObject() {
-        logger.debug(new Date());
-        assertThat(list.strList, hasSize(1));
-    }
-
-    @Test
-    public void debugWithParms() {
-        logger.debug("Hello, {}", "World");
-        assertThat(list.strList, hasSize(1));
-    }
-
-    @Test
-    public void testImpliedThrowable() {
-        logger.debug("This is a test", new Throwable("Testing"));
-        final List<String> msgs = list.strList;
-        assertThat(msgs, hasSize(1));
-        final String expected = "java.lang.Throwable: Testing";
-        assertTrue("Incorrect message data", msgs.get(0).contains(expected));
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void mdc() {
-        ThreadContext.put("TestYear", Integer.toString(2010));
-        logger.debug("Debug message");
-        ThreadContext.clearMap();
-        logger.debug("Debug message");
-        assertThat(list.strList, hasSize(2));
-        assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
-    }
-}
-
+
+/*
+* 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.slf4j;
+
+import java.util.Date;
+import java.util.List;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.testUtil.StringListAppender;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.message.ParameterizedMessageFactory;
+import org.apache.logging.log4j.message.StringFormatterMessageFactory;
+import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.spi.MessageFactory2Adapter;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class LoggerTest {
+
+    private static final String CONFIG = "target/test-classes/logback-slf4j.xml";
+
+    @ClassRule
+    public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG);
+
+    private Logger logger;
+    private StringListAppender<ILoggingEvent> list;
+
+    @Before
+    public void setUp() throws Exception {
+        final org.slf4j.Logger slf4jLogger = CTX.getLogger();
+        logger = LogManager.getLogger();
+        assertThat(slf4jLogger, is(theInstance(((SLF4JLogger) logger).getLogger())));
+        final ch.qos.logback.classic.Logger rootLogger = CTX.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
+        rootLogger.detachAppender("console");
+        list = TestUtil.getListAppender(rootLogger, "LIST");
+        assertThat(list, is(notNullValue()));
+        assertThat(list.strList, is(notNullValue()));
+        list.strList.clear();
+    }
+
+    @Test
+    public void basicFlow() {
+        logger.traceEntry();
+        logger.traceExit();
+        assertThat(list.strList, hasSize(2));
+    }
+
+    @Test
+    public void basicFlowDepreacted() {
+        logger.entry();
+        logger.exit();
+        assertThat(list.strList, hasSize(2));
+    }
+
+    @Test
+    public void simpleFlowDeprecated() {
+        logger.entry(CONFIG);
+        logger.exit(0);
+        assertThat(list.strList, hasSize(2));
+    }
+
+    @Test
+    public void simpleFlow() {
+        logger.entry(CONFIG);
+        logger.traceExit(0);
+        assertThat(list.strList, hasSize(2));
+    }
+
+    @Test
+    public void throwing() {
+        logger.throwing(new IllegalArgumentException("Test Exception"));
+        assertThat(list.strList, hasSize(1));
+    }
+
+    @Test
+    public void catching() {
+        try {
+            throw new NullPointerException();
+        } catch (final Exception e) {
+            logger.catching(e);
+        }
+        assertThat(list.strList, hasSize(1));
+    }
+
+    @Test
+    public void debug() {
+        logger.debug("Debug message");
+        assertThat(list.strList, hasSize(1));
+    }
+
+    @Test
+    public void getLogger_String_MessageFactoryMismatch() {
+        final Logger testLogger = testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
+            StringFormatterMessageFactory.INSTANCE, ParameterizedMessageFactory.INSTANCE);
+        testLogger.debug("%,d", Integer.MAX_VALUE);
+        assertThat(list.strList, hasSize(1));
+        assertThat(list.strList, hasItem(String.format("%,d", Integer.MAX_VALUE)));
+    }
+
+    @Test
+    public void getLogger_String_MessageFactoryMismatchNull() {
+        final Logger testLogger =  testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatchNull",
+            StringFormatterMessageFactory.INSTANCE, null);
+        testLogger.debug("%,d", Integer.MAX_VALUE);
+        assertThat(list.strList, hasSize(1));
+        assertThat(list.strList, hasItem(String.format("%,d", Integer.MAX_VALUE)));
+    }
+
+    private Logger testMessageFactoryMismatch(final String name, final MessageFactory messageFactory1, final MessageFactory messageFactory2) {
+        final Logger testLogger = LogManager.getLogger(name, messageFactory1);
+        assertThat(testLogger, is(notNullValue()));
+        checkMessageFactory(messageFactory1, testLogger);
+        final Logger testLogger2 = LogManager.getLogger(name, messageFactory2);
+        checkMessageFactory(messageFactory1, testLogger2);
+        return testLogger;
+    }
+
+    private static void checkMessageFactory(final MessageFactory messageFactory1, final Logger testLogger1) {
+        if (messageFactory1 == null) {
+            assertEquals(AbstractLogger.DEFAULT_MESSAGE_FACTORY_CLASS, testLogger1.getMessageFactory().getClass());
+        } else {
+            MessageFactory actual = testLogger1.getMessageFactory();
+            if (actual instanceof MessageFactory2Adapter) {
+                actual = ((MessageFactory2Adapter) actual).getOriginal();
+            }
+            assertEquals(messageFactory1, actual);
+        }
+    }
+
+    @Test
+    public void debugObject() {
+        logger.debug(new Date());
+        assertThat(list.strList, hasSize(1));
+    }
+
+    @Test
+    public void debugWithParms() {
+        logger.debug("Hello, {}", "World");
+        assertThat(list.strList, hasSize(1));
+    }
+
+    @Test
+    public void testImpliedThrowable() {
+        logger.debug("This is a test", new Throwable("Testing"));
+        final List<String> msgs = list.strList;
+        assertThat(msgs, hasSize(1));
+        final String expected = "java.lang.Throwable: Testing";
+        assertTrue("Incorrect message data", msgs.get(0).contains(expected));
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void mdc() {
+        ThreadContext.put("TestYear", Integer.toString(2010));
+        logger.debug("Debug message");
+        ThreadContext.clearMap();
+        logger.debug("Debug message");
+        assertThat(list.strList, hasSize(2));
+        assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
+    }
+}
+


[22/50] logging-log4j2 git commit: LOG4J2-1297 latency test javadoc

Posted by mi...@apache.org.
LOG4J2-1297 latency test javadoc


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

Branch: refs/heads/LOG4J2-1365
Commit: 3c37ca34db7ada0d7bb20de5a3cd1caf4f4eced7
Parents: c5f5cc9
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 22:42:54 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 22:42:54 2016 +0900

----------------------------------------------------------------------
 .../core/async/perftest/SimpleLatencyTest.java  | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3c37ca34/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
index f7459b6..1a306b1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
@@ -26,7 +26,34 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
 /**
- *
+ * Latency test.
+ * <p>
+ * See <a href="https://groups.google.com/d/msg/mechanical-sympathy/0gaBXxFm4hE/O9QomwHIJAAJ">https://groups.google.com/d/msg/mechanical-sympathy/0gaBXxFm4hE/O9QomwHIJAAJ</a>:
+ * </p>
+ * <p>Gil Tene's rules of thumb for latency tests:</p>
+ * <ol>
+ * <li>DO measure max achievable throughput, but DON'T get focused on it as the main or single axis of measurement /
+ * comparison.</li>
+ * <li>DO measure response time / latency behaviors across a spectrum of attempted load levels (e.g. at attempted loads
+ * between 2% to 100%+ of max established thoughout).</li>
+ * <li>DO measure the response time / latency spectrum for each tested load (even for max throughout, for which response
+ * time should linearly grow with test length, or the test is wrong). HdrHistogram is one good way to capture this
+ * information.</li>
+ * <li>DO make sure you are measuring response time correctly and labeling it right. If you also measure and report
+ * service time, label it as such (don't call it "latency").
+ * <li>DO compare response time / latency spectrum at given loads.</li>
+ * <li>DO [repeatedly] sanity check and calibrate the benchmark setup to verify that it produces expected results for
+ * known forced scenarios. E.g. forced pauses of known size via ^Z or SIGSTOP/SIGCONT should produce expected response
+ * time percentile levels. Attempting to load at >100% than achieved throughput should result in response time / latency
+ * measurements that grow with benchmark run length, while service time (if measured) should remain fairly flat well
+ * past saturation.</li>
+ * <li>DON'T use or report standard deviation for latency. Ever. Except if you mean it as a joke.</li>
+ * <li>DON'T use average latency as a way to compare things with one another. [use median or 90%'ile instead, if what
+ * you want to compare is "common case" latencies]. Consider not reporting avg. at all.</li>
+ * <li>DON'T compare results of different setups or loads from short runs (< 20-30 minutes).</li>
+ * <li>DON'T include process warmup behavior (e.g. 1st minute and 1st 50K messages) in compared or reported results.
+ * </li>
+ * </ol>
  */
 public class SimpleLatencyTest {
     private static final String LATENCY_MSG = new String(new char[64]);
@@ -61,7 +88,7 @@ public class SimpleLatencyTest {
 
         List<Histogram> histograms = new ArrayList<>(threadCount);
 
-        for (int i = 0 ; i < 30; i++) {
+        for (int i = 0; i < 30; i++) {
             final int ITERATIONS = 100 * 1000;// * 30;
             runLatencyTest(logger, ITERATIONS, interval, idleStrategy, histograms, nanoTimeCost, threadCount);
 


[43/50] logging-log4j2 git commit: Add traceEntry/Exit() tests.

Posted by mi...@apache.org.
Add traceEntry/Exit() tests.

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

Branch: refs/heads/LOG4J2-1365
Commit: 7380b27e15465d943cdeecb6ec35430859406256
Parents: b61fbbd
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:59:03 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:59:03 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/LoggerTest.java  | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7380b27e/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
index 7ba6a89..7a2e01e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
@@ -89,8 +89,8 @@ public class LoggerTest {
 
     @Test
     public void basicFlow() {
-        logger.entry();
-        logger.exit();
+        logger.traceEntry();
+        logger.traceExit();
         final List<LogEvent> events = app.getEvents();
         assertEventCount(events, 2);
     }
@@ -98,6 +98,14 @@ public class LoggerTest {
     @Test
     public void simpleFlow() {
         logger.entry(CONFIG);
+        logger.traceExit(0);
+        final List<LogEvent> events = app.getEvents();
+        assertEventCount(events, 2);
+    }
+
+    @Test
+    public void simpleFlowDepreacted() {
+        logger.entry(CONFIG);
         logger.exit(0);
         final List<LogEvent> events = app.getEvents();
         assertEventCount(events, 2);


[25/50] logging-log4j2 git commit: Fix appender name.

Posted by mi...@apache.org.
Fix appender name.

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

Branch: refs/heads/LOG4J2-1365
Commit: 51142337af823fd49dcfee17527cefd424e5fe6c
Parents: 98cc7d2
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 15:46:45 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 15:46:45 2016 -0700

----------------------------------------------------------------------
 log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/51142337/log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml b/log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml
index 0f83ae5..7298437 100644
--- a/log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml
+++ b/log4j-core/src/test/resources/JsonCompleteFileAppenderTest.xml
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Configuration status="OFF">
   <Appenders>
-    <File name="XmlFile" fileName="target/JsonCompleteFileAppenderTest.log" immediateFlush="true" append="false">
+    <File name="JsonFile" fileName="target/JsonCompleteFileAppenderTest.log" immediateFlush="true" append="false">
       <JSONLayout complete="true" charset="UTF-8"/>
     </File>
   </Appenders>
 
   <Loggers>
     <Root level="info" includeLocation="false">
-      <AppenderRef ref="XmlFile"/>
+      <AppenderRef ref="JsonFile"/>
     </Root>
   </Loggers>
 </Configuration>


[29/50] logging-log4j2 git commit: Remove unused imports.

Posted by mi...@apache.org.
Remove unused imports.

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

Branch: refs/heads/LOG4J2-1365
Commit: 1494ce222b9909f7a22d8c1da03778afc00631da
Parents: 8778064
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:30:32 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:30:32 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/message/SimpleMessage.java |  2 --
 .../java/org/apache/logging/log4j/util/Unbox.java   |  2 --
 .../log4j/message/ParameterFormatterTest.java       |  2 --
 .../log4j/core/async/AsyncEventRouterFactory.java   |  2 --
 .../pattern/ExtendedThrowablePatternConverter.java  |  1 -
 .../core/pattern/RootThrowablePatternConverter.java |  1 -
 .../log4j/core/GcFreeMixedSyncAyncLoggingTest.java  | 15 ---------------
 .../log4j/core/GcFreeSynchronousLoggingTest.java    | 16 ----------------
 .../log4j/core/impl/MutableLogEventTest.java        |  2 --
 9 files changed, 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
index 31d35b1..6ffc9df 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
@@ -19,8 +19,6 @@ package org.apache.logging.log4j.message;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
 import org.apache.logging.log4j.util.StringBuilderFormattable;
 
 /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
index 6981fb8..8c1c8a7 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Unbox.java
@@ -16,8 +16,6 @@
  */
 package org.apache.logging.log4j.util;
 
-import static org.apache.logging.log4j.util.Unbox.box;
-
 /**
  * Utility for preventing primitive parameter values from being auto-boxed. Auto-boxing creates temporary objects
  * which contribute to pressure on the garbage collector. With this utility users can convert primitive values directly

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-api/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
index e6a0dbd..625b1b8 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
@@ -18,8 +18,6 @@ package org.apache.logging.log4j.message;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
-
 import org.junit.Test;
 
 import static org.junit.Assert.*;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/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 d4f0d8a..a412486 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
@@ -16,8 +16,6 @@
  */
 package org.apache.logging.log4j.core.async;
 
-import java.lang.reflect.Constructor;
-
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
index 84d4e65..2a74a46 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
@@ -18,7 +18,6 @@ package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.ThrowableProxy;
 import org.apache.logging.log4j.core.util.Constants;
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
index 2c75cfc..317842d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
@@ -18,7 +18,6 @@ package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.ThrowableProxy;
 import org.apache.logging.log4j.core.util.Constants;
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
index e954640..b917f93 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
@@ -16,24 +16,9 @@
  */
 package org.apache.logging.log4j.core;
 
-import java.io.File;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.MarkerManager;
-import org.apache.logging.log4j.core.util.Constants;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
-import com.google.monitoring.runtime.instrumentation.Sampler;
-
-import static org.junit.Assert.*;
-
 /**
  * Verifies steady state mixed synchronous and asynchronous logging is GC-free.
  *

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
index 11dd182..9a01c22 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
@@ -16,25 +16,9 @@
  */
 package org.apache.logging.log4j.core;
 
-import java.io.File;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.MarkerManager;
-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 com.google.monitoring.runtime.instrumentation.AllocationRecorder;
-import com.google.monitoring.runtime.instrumentation.Sampler;
-
-import static org.junit.Assert.*;
-
 /**
  * Verifies steady state synchronous logging is GC-free.
  *

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1494ce22/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
index 23a49f4..47bb5a7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
@@ -20,10 +20,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.spi.MutableThreadContextStack;
 import org.junit.Test;


[20/50] logging-log4j2 git commit: LOG4J2-1334 improved and added gc-free unit tests:

Posted by mi...@apache.org.
LOG4J2-1334 improved and added gc-free unit tests:

- Move shared logic to new class GcFreeLoggingTestUtil
- Renamed GcFreeLoggingTest to GcFreeAsynchronousLoggingTest
- Added GcFreeSynchronousLoggingTest
- Added GcFreeMixedSyncAsyncLoggingTest with config gcFreeMixedSyncAsyncLogging.xml


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

Branch: refs/heads/LOG4J2-1365
Commit: 8ebed8fc0e87d0bc1a95b1a9851702ac336c9374
Parents: 3706664
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 22:17:01 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 22:17:01 2016 +0900

----------------------------------------------------------------------
 .../core/GcFreeAsynchronousLoggingTest.java     |  41 +++++
 .../logging/log4j/core/GcFreeLoggingTest.java   | 173 -------------------
 .../log4j/core/GcFreeLoggingTestUtil.java       | 169 ++++++++++++++++++
 .../core/GcFreeMixedSyncAyncLoggingTest.java    |  58 +++++++
 .../core/GcFreeSynchronousLoggingTest.java      |  58 +++++++
 .../resources/gcFreeMixedSyncAsyncLogging.xml   |  71 ++++++++
 6 files changed, 397 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
new file mode 100644
index 0000000..a74a35b
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
+import org.junit.Test;
+
+/**
+ * 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 GcFreeAsynchronousLoggingTest {
+
+    @Test
+    public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
+        GcFreeLoggingTestUtil.runTest(getClass());
+    }
+
+    /**
+     * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
+     */
+    public static void main(String[] args) throws Exception {
+        System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
+        GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeAsynchronousLoggingTest.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/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
deleted file mode 100644
index c66bae3..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
+++ /dev/null
@@ -1,173 +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;
-
-import java.io.File;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.MarkerManager;
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
-import org.apache.logging.log4j.core.util.Constants;
-import org.junit.Test;
-
-import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
-import com.google.monitoring.runtime.instrumentation.Sampler;
-
-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 {
-
-    private static class MyCharSeq implements CharSequence {
-        final String seq = GcFreeLoggingTest.class.toString();
-
-        @Override
-        public int length() {
-            return seq.length();
-        }
-
-        @Override
-        public char charAt(final int index) {
-            return seq.charAt(index);
-        }
-
-        @Override
-        public CharSequence subSequence(final int start, final int end) {
-            return seq.subSequence(start, end);
-        }
-
-        @Override
-        public String toString() {
-            System.err.println("TEMP OBJECT CREATED!");
-            throw new IllegalStateException("TEMP OBJECT CREATED!");
-        }
-    }
-
-    @Test
-    public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
-        if (!Constants.ENABLE_THREADLOCALS || !Constants.ENABLE_DIRECT_ENCODERS) {
-            return;
-        }
-        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 List<String> lines = Files.readAllLines(tempFile.toPath(), Charset.defaultCharset());
-        assertEquals("FATAL o.a.l.l.c.GcFreeLoggingTest [main]  This message is logged to the console",
-                lines.get(0));
-
-        for (int i = 1; i < lines.size(); i++) {
-            final String line = lines.get(i);
-            assertFalse(line, line.contains("allocated") || line.contains("array"));
-        }
-    }
-
-    /**
-     * 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", "gcFreeLogging.xml");
-        System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
-
-        assertTrue("Constants.ENABLE_THREADLOCALS", Constants.ENABLE_THREADLOCALS);
-        assertFalse("Constants.IS_WEB_APP", Constants.IS_WEB_APP);
-
-        MyCharSeq myCharSeq = new MyCharSeq();
-        MarkerManager.getMarker("test"); // initial creation, value is cached
-
-        // 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.fatal("This message is logged to the console");
-        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.err.println("I just allocated the object " + newObj +
-                        " of type " + desc + " whose size is " + size);
-                if (count != -1) {
-                    System.err.println("It's an array of size " + count);
-                }
-
-                // show a stack trace to 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(myCharSeq);
-            logger.error(MarkerManager.getMarker("test"), myCharSeq);
-            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");
-        }
-        Thread.sleep(50);
-        AllocationRecorder.removeSampler(sampler);
-        Thread.sleep(100);
-    }
-
-    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);
-    }
-}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
new file mode 100644
index 0000000..e5b205c
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
@@ -0,0 +1,169 @@
+/*
+ * 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.charset.Charset;
+import java.nio.file.Files;
+import java.util.List;
+
+import org.apache.logging.log4j.*;
+import org.apache.logging.log4j.core.util.Constants;
+
+import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
+import com.google.monitoring.runtime.instrumentation.Sampler;
+
+import static org.junit.Assert.*;
+
+/**
+ * Utily methods for the GC-free logging tests.s.
+ */
+public class GcFreeLoggingTestUtil {
+
+    public static void executeLogging(final String configurationFile,
+            final Class<?> testClass) throws Exception {
+
+        System.setProperty("log4j2.enable.threadlocals", "true");
+        System.setProperty("log4j2.enable.direct.encoders", "true");
+        System.setProperty("log4j2.is.webapp", "false");
+        System.setProperty("log4j.configurationFile", configurationFile);
+
+        assertTrue("Constants.ENABLE_THREADLOCALS", Constants.ENABLE_THREADLOCALS);
+        assertTrue("Constants.ENABLE_DIRECT_ENCODERS", Constants.ENABLE_DIRECT_ENCODERS);
+        assertFalse("Constants.IS_WEB_APP", Constants.IS_WEB_APP);
+
+        MyCharSeq myCharSeq = new MyCharSeq();
+        MarkerManager.getMarker("test"); // initial creation, value is cached
+
+        // initialize LoggerContext etc.
+        // This is not steady-state logging and will allocate objects.
+        final org.apache.logging.log4j.Logger logger = LogManager.getLogger(testClass.getName());
+        logger.debug("debug not set");
+        logger.fatal("This message is logged to the console");
+        logger.error("Sample error message");
+        logger.error("Test parameterized message {}", "param");
+        for (int i = 0; i < 128; i++) {
+            logger.debug("ensure all ringbuffer slots have been used once"); // allocate MutableLogEvent.messageText
+        }
+
+        // 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.err.println("I just allocated the object " + newObj +
+                        " of type " + desc + " whose size is " + size);
+                if (count != -1) {
+                    System.err.println("It's an array of size " + count);
+                }
+
+                // show a stack trace to 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(myCharSeq);
+            logger.error(MarkerManager.getMarker("test"), myCharSeq);
+            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");
+        }
+        Thread.sleep(50);
+        AllocationRecorder.removeSampler(sampler);
+        Thread.sleep(100);
+    }
+
+    public static void runTest(Class<?> cls) throws Exception {
+        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, cls.getName());
+        builder.redirectError(ProcessBuilder.Redirect.to(tempFile));
+        builder.redirectOutput(ProcessBuilder.Redirect.to(tempFile));
+        final Process process = builder.start();
+        process.waitFor();
+        process.exitValue();
+
+        final String text = new String(Files.readAllBytes(tempFile.toPath()));
+        final List<String> lines = Files.readAllLines(tempFile.toPath(), Charset.defaultCharset());
+        final String className = cls.getSimpleName();
+        assertEquals(text, "FATAL o.a.l.l.c." + className + " [main]  This message is logged to the console",
+                lines.get(0));
+
+        final String LINESEP = System.getProperty("line.separator");
+        for (int i = 1; i < lines.size(); i++) {
+            final String line = lines.get(i);
+            assertFalse(i + ": " + line + LINESEP + text, line.contains("allocated") || line.contains("array"));
+        }
+    }
+
+    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);
+    }
+
+    public static class MyCharSeq implements CharSequence {
+        final String seq = GcFreeLoggingTestUtil.class.toString();
+
+        @Override
+        public int length() {
+            return seq.length();
+        }
+
+        @Override
+        public char charAt(final int index) {
+            return seq.charAt(index);
+        }
+
+        @Override
+        public CharSequence subSequence(final int start, final int end) {
+            return seq.subSequence(start, end);
+        }
+
+        @Override
+        public String toString() {
+            System.err.println("TEMP OBJECT CREATED!");
+            throw new IllegalStateException("TEMP OBJECT CREATED!");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
new file mode 100644
index 0000000..e954640
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.charset.Charset;
+import java.nio.file.Files;
+import java.util.List;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.MarkerManager;
+import org.apache.logging.log4j.core.util.Constants;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.google.monitoring.runtime.instrumentation.AllocationRecorder;
+import com.google.monitoring.runtime.instrumentation.Sampler;
+
+import static org.junit.Assert.*;
+
+/**
+ * Verifies steady state mixed synchronous and asynchronous logging is GC-free.
+ *
+ * @see <a href="https://github.com/google/allocation-instrumenter">https://github.com/google/allocation-instrumenter</a>
+ */
+public class GcFreeMixedSyncAyncLoggingTest {
+
+    // Ignore until mixed synchronous/asynchronous logging is gc-free
+    @Ignore
+    @Test
+    public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
+        GcFreeLoggingTestUtil.runTest(getClass());
+    }
+
+    /**
+     * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
+     */
+    public static void main(String[] args) throws Exception {
+        System.setProperty("AsyncLoggerConfig.RingBufferSize", "128"); // minimum ringbuffer size
+        GcFreeLoggingTestUtil.executeLogging("gcFreeMixedSyncAsyncLogging.xml", GcFreeMixedSyncAyncLoggingTest.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
new file mode 100644
index 0000000..11dd182
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.charset.Charset;
+import java.nio.file.Files;
+import java.util.List;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.MarkerManager;
+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 com.google.monitoring.runtime.instrumentation.AllocationRecorder;
+import com.google.monitoring.runtime.instrumentation.Sampler;
+
+import static org.junit.Assert.*;
+
+/**
+ * Verifies steady state synchronous logging is GC-free.
+ *
+ * @see <a href="https://github.com/google/allocation-instrumenter">https://github.com/google/allocation-instrumenter</a>
+ */
+public class GcFreeSynchronousLoggingTest {
+
+    // Ignore until synchronous logging is gc-free
+    @Ignore
+    @Test
+    public void testNoAllocationDuringSteadyStateLogging() throws Throwable {
+        GcFreeLoggingTestUtil.runTest(getClass());
+    }
+
+    /**
+     * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
+     */
+    public static void main(String[] args) throws Exception {
+        GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeSynchronousLoggingTest.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8ebed8fc/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml b/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
new file mode 100644
index 0000000..e4c0000
--- /dev/null
+++ b/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="OFF">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %m%ex%n" />
+    </Console>
+    <File name="File" fileName="target/gcfreefileMixed.log" bufferedIO="false">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+    </File>
+    <RollingFile name="RollingFile" fileName="target/gcfreeRollingFileMixed.log"
+        filePattern="target/gcfree-%d{MM-dd-yy-HH-mm-ss}.log.gz">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
+      </PatternLayout>
+      <Policies>
+        <SizeBasedTriggeringPolicy size="50M" />
+      </Policies>
+    </RollingFile>
+    <RandomAccessFile name="RandomAccessFile" fileName="target/gcfreeRAFMixed.log" immediateFlush="false" append="false">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %ex%n</Pattern>
+      </PatternLayout>
+    </RandomAccessFile>
+    <RollingRandomAccessFile name="RollingRandomAccessFile"
+        fileName="target/gcfreeRRAFMixed.log"
+        filePattern="target/afterRollover-%i.log" append="false"
+        immediateFlush="false">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
+      </PatternLayout>
+      <Policies>
+        <SizeBasedTriggeringPolicy size="50 M"/>
+      </Policies>
+    </RollingRandomAccessFile>
+    <MemoryMappedFile name="MemoryMappedFile"
+        fileName="target/gcfreemmapMixed.log"
+        immediateFlush="false" append="false">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %X{aKey} %m%ex%n</Pattern>
+      </PatternLayout>
+    </MemoryMappedFile>
+    <RandomAccessFile name="RandomAccessFileGelf" fileName="target/gcfreeMixed.json" immediateFlush="false" append="false">
+       <GelfLayout compressionType="OFF"/>
+    </RandomAccessFile>
+  </Appenders>
+  <Loggers>
+    <AsyncLogger name="org.apache.logging.log4j.core.GcFreeMixedSyncAyncLoggingTest"
+        level="info" includeLocation="false">
+      <appender-ref ref="Console" level="FATAL" />
+      <appender-ref ref="File"/>
+      <appender-ref ref="RandomAccessFile"/>
+      <appender-ref ref="RollingRandomAccessFile"/>
+      <appender-ref ref="File"/>
+      <appender-ref ref="RollingFile"/>
+      <appender-ref ref="MemoryMappedFile"/>
+      <appender-ref ref="RandomAccessFileGelf"/>
+    </AsyncLogger>
+    <Root level="info" includeLocation="false">
+      <appender-ref ref="Console" level="FATAL" />
+      <appender-ref ref="File"/>
+      <appender-ref ref="RandomAccessFile"/>
+      <appender-ref ref="RollingRandomAccessFile"/>
+      <appender-ref ref="File"/>
+      <appender-ref ref="RollingFile"/>
+      <appender-ref ref="MemoryMappedFile"/>
+      <appender-ref ref="RandomAccessFileGelf"/>
+    </Root>
+  </Loggers>
+</Configuration>


[03/50] logging-log4j2 git commit: removed trailing whitespace

Posted by mi...@apache.org.
removed trailing whitespace


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

Branch: refs/heads/LOG4J2-1365
Commit: e6d1b9768f09b504c9667e9160261459859f308b
Parents: d9a373f
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 16:33:51 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 16:33:51 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e6d1b976/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
index b27bce6..f6cc708 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
@@ -48,7 +48,7 @@ class Initializers {
             context.setMixInAnnotations(LogEvent.class, LogEventMixIn.class);
             // Log4j Core classes: we do not want to bring in Jackson at runtime if we do not have to.
             context.setMixInAnnotations(ExtendedStackTraceElement.class, ExtendedStackTraceElementMixIn.class);
-            context.setMixInAnnotations(ThrowableProxy.class, ThrowableProxyMixIn.class);            
+            context.setMixInAnnotations(ThrowableProxy.class, ThrowableProxyMixIn.class);
         }
     }
 


[50/50] logging-log4j2 git commit: Fix compilation errors

Posted by mi...@apache.org.
Fix compilation errors


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

Branch: refs/heads/LOG4J2-1365
Commit: 86934ca41c41bb4cfc950b8fc1e65b0aab374ef6
Parents: 86f30cf
Author: Mikael Ståldal <mi...@magine.com>
Authored: Mon Apr 18 13:37:31 2016 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Mon Apr 18 13:37:31 2016 +0200

----------------------------------------------------------------------
 .../test/java/org/apache/logging/log4j/AbstractLoggerTest.java | 6 +++---
 .../org/apache/logging/log4j/core/TimestampMessageTest.java    | 3 ++-
 .../log4j/core/async/AsyncLoggerTimestampMessageTest.java      | 3 ++-
 .../org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java     | 5 +++--
 4 files changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86934ca4/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
index 3fd165d..d973610 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
@@ -165,7 +165,7 @@ public class AbstractLoggerTest extends AbstractLogger {
     @Override
     public boolean isEnabled(final Level level, final Marker marker, final CharSequence data, final Throwable t) {
         charSeqCount++;
-        return isEnabled(level, marker, new SimpleMessage(data), t);
+        return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
     }
 
     @Override
@@ -176,7 +176,7 @@ public class AbstractLoggerTest extends AbstractLogger {
 
     @Override
     public boolean isEnabled(final Level level, final Marker marker, final String data) {
-        return isEnabled(level, marker, new SimpleMessage(data), null);
+        return isEnabled(level, marker, (Message) new SimpleMessage(data), null);
     }
 
     @Override
@@ -255,7 +255,7 @@ public class AbstractLoggerTest extends AbstractLogger {
 
     @Override
     public boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) {
-        return isEnabled(level, marker, new SimpleMessage(data), t);
+        return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86934ca4/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
index d76e613..60d643b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.core.util.ClockFactoryTest;
 import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.message.TimestampMessage;
 import org.apache.logging.log4j.test.appender.ListAppender;
@@ -67,7 +68,7 @@ public class TimestampMessageTest {
     @Test
     public void testTimestampMessage() {
         final Logger log = context.getLogger("TimestampMessageTest");
-        log.info(new TimeMsg("Message with embedded timestamp", 123456789000L));
+        log.info((Message) new TimeMsg("Message with embedded timestamp", 123456789000L));
         final List<String> msgs = app.getMessages();
         assertNotNull(msgs);
         assertEquals(1, msgs.size());

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86934ca4/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
index 34198a0..e540353 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
@@ -28,6 +28,7 @@ import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.core.util.ClockFactoryTest;
 import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.message.TimestampMessage;
 import org.apache.logging.log4j.util.Strings;
@@ -69,7 +70,7 @@ public class AsyncLoggerTimestampMessageTest {
         file.delete();
         final Logger log = LogManager.getLogger("com.foo.Bar");
         assertFalse(PoisonClock.called);
-        log.info(new TimeMsg("Async logger msg with embedded timestamp", 123456789000L));
+        log.info((Message) new TimeMsg("Async logger msg with embedded timestamp", 123456789000L));
         assertTrue(PoisonClock.called);
         CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86934ca4/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
index 8d1f189..37814c7 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -92,7 +93,7 @@ public class SimpleBenchmark {
     @OutputTimeUnit(TimeUnit.SECONDS)
     @Benchmark
     public void testDebugMessageDisabledThroughput(final Blackhole bh) {
-        logger.debug(new SimpleMessage(msg));
+        logger.debug((Message) new SimpleMessage(msg));
     }
 
     @BenchmarkMode(Mode.SampleTime)
@@ -126,6 +127,6 @@ public class SimpleBenchmark {
     @OutputTimeUnit(TimeUnit.NANOSECONDS)
     @Benchmark
     public void testDebugDisabledMessageResponseTime(final Blackhole bh) {
-        logger.debug(new SimpleMessage(msg));
+        logger.debug((Message) new SimpleMessage(msg));
     }
 }


[09/50] logging-log4j2 git commit: LOG4J2-1334 the kill switch for MutableLogEvents (currently short-circuited so it always uses Log4jLogEvent)

Posted by mi...@apache.org.
LOG4J2-1334 the kill switch for MutableLogEvents (currently short-circuited so it always uses Log4jLogEvent)


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

Branch: refs/heads/LOG4J2-1365
Commit: 328a8bf8f0d80b466d2d5c666c9f7a31d70ba678
Parents: cedf155
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:52:39 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:52:39 2016 +0900

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/config/LoggerConfig.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/328a8bf8/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index e5eb9d4..7b030c6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -40,6 +40,7 @@ import org.apache.logging.log4j.core.filter.AbstractFilterable;
 import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.LogEventFactory;
+import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.core.util.Booleans;
 import org.apache.logging.log4j.core.util.Constants;
@@ -83,7 +84,9 @@ public class LoggerConfig extends AbstractFilterable {
             }
         }
         if (LOG_EVENT_FACTORY == null) {
-            LOG_EVENT_FACTORY = new DefaultLogEventFactory();
+            LOG_EVENT_FACTORY = false //Constants.ENABLE_THREADLOCALS
+                    ? new ReusableLogEventFactory()
+                    : new DefaultLogEventFactory();
         }
     }
 


[27/50] logging-log4j2 git commit: Add missing '@Override' annotations.

Posted by mi...@apache.org.
Add missing '@Override' annotations.

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

Branch: refs/heads/LOG4J2-1365
Commit: 99b5a5defb1a1e6640da1ede814b6d3c9897bbe2
Parents: ffbd8c9
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:28:52 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:28:52 2016 -0700

----------------------------------------------------------------------
 .../src/test/java/org/apache/logging/log4j/util/UnboxTest.java     | 2 ++
 .../logging/log4j/core/appender/rolling/PatternProcessor.java      | 1 +
 .../logging/log4j/core/async/perftest/SimpleLatencyTest.java       | 1 +
 .../org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java  | 1 +
 4 files changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/99b5a5de/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxTest.java
index 966fa6a..e0b2766 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxTest.java
@@ -119,6 +119,7 @@ public class UnboxTest {
         final StringBuilder[] probe = new StringBuilder[16 * 3];
         populate(0, probe);
         Thread t1 = new Thread() {
+            @Override
             public void run() {
                 populate(16, probe);
             }
@@ -126,6 +127,7 @@ public class UnboxTest {
         t1.start();
         t1.join();
         Thread t2 = new Thread() {
+            @Override
             public void run() {
                 populate(16, probe);
             }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/99b5a5de/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
index e441c69..0dee11e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
@@ -64,6 +64,7 @@ public class PatternProcessor {
         return pattern;
     }
 
+    @Override
     public String toString() {
         return pattern;
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/99b5a5de/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
index 1a306b1..90341ad 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
@@ -111,6 +111,7 @@ public class SimpleLatencyTest {
             final Histogram hist = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
             histograms.add(hist);
             final Thread t = new Thread("latencytest-" + i) {
+                @Override
                 public void run() {
                     LATCH.countDown();
                     try {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/99b5a5de/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java
index 55853fa..f2e63e5 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInJsonTest.java
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class LevelMixInJsonTest extends LevelMixInTest {
 
+    @Override
     protected ObjectMapper newObjectMapper() {
         return new Log4jJsonObjectMapper();
     }


[42/50] logging-log4j2 git commit: Remove unused imports.

Posted by mi...@apache.org.
Remove unused imports.

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

Branch: refs/heads/LOG4J2-1365
Commit: b61fbbd4c4516fea90fedeb22777ac13cd089b1b
Parents: a7f60a2
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:56:39 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:56:39 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/core/appender/MemoryMappedFileManager.java | 1 -
 .../apache/logging/log4j/core/appender/RandomAccessFileManager.java | 1 -
 .../log4j/core/appender/rolling/RollingRandomAccessFileManager.java | 1 -
 3 files changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index 1986993..cfb5a08 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -34,7 +34,6 @@ import java.util.Map;
 import java.util.Objects;
 
 import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.util.Closer;
 import org.apache.logging.log4j.core.util.NullOutputStream;
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
index 674c25f..265aef0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
@@ -26,7 +26,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.util.NullOutputStream;
 
 /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index e76dba6..7a3e43d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -26,7 +26,6 @@ import java.nio.ByteBuffer;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.util.NullOutputStream;
 
 /**


[41/50] logging-log4j2 git commit: Statement unnecessarily nested.

Posted by mi...@apache.org.
Statement unnecessarily nested.


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

Branch: refs/heads/LOG4J2-1365
Commit: a7f60a25a89126cd183ed5181ab526fcfbd213c2
Parents: 9a563a6
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:55:32 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:55:32 2016 -0700

----------------------------------------------------------------------
 .../appender/rolling/action/DeleteAction.java   | 432 +++++++++----------
 .../logging/log4j/core/impl/Log4jLogEvent.java  |   3 +-
 .../logging/log4j/core/layout/GelfLayout.java   |   9 +-
 .../core/pattern/DatePatternConverter.java      |   3 +-
 4 files changed, 220 insertions(+), 227 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
index c2c385f..8176470 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
@@ -1,218 +1,214 @@
-/*
- * 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.appender.rolling.action;
-
-import java.io.IOException;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Objects;
-
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
-
-/**
- * Rollover or scheduled action for deleting old log files that are accepted by the specified PathFilters.
- */
-@Plugin(name = "Delete", category = "Core", printObject = true)
-public class DeleteAction extends AbstractPathAction {
-
-    private final PathSorter pathSorter;
-    private final boolean testMode;
-    private final ScriptCondition scriptCondition;
-
-    /**
-     * Creates a new DeleteAction that starts scanning for files to delete from the specified base path.
-     * 
-     * @param basePath base path from where to start scanning for files to delete.
-     * @param followSymbolicLinks whether to follow symbolic links. Default is false.
-     * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
-     *            means that only the starting file is visited, unless denied by the security manager. A value of
-     *            MAX_VALUE may be used to indicate that all levels should be visited.
-     * @param testMode if true, files are not deleted but instead a message is printed to the <a
-     *            href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
-     *            at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
-     * @param sorter sorts
-     * @param pathConditions an array of path filters (if more than one, they all need to accept a path before it is
-     *            deleted).
-     * @param scriptCondition
-     */
-    DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, final boolean testMode,
-            final PathSorter sorter, final PathCondition[] pathConditions, final ScriptCondition scriptCondition,
-            final StrSubstitutor subst) {
-        super(basePath, followSymbolicLinks, maxDepth, pathConditions, subst);
-        this.testMode = testMode;
-        this.pathSorter = Objects.requireNonNull(sorter, "sorter");
-        this.scriptCondition = scriptCondition;
-        if (scriptCondition == null && (pathConditions == null || pathConditions.length == 0)) {
-            LOGGER.error("Missing Delete conditions: unconditional Delete not supported");
-            throw new IllegalArgumentException("Unconditional Delete not supported");
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute()
-     */
-    @Override
-    public boolean execute() throws IOException {
-        if (scriptCondition != null) {
-            return executeScript();
-        } else {
-            return super.execute();
-        }
-    }
-
-    private boolean executeScript() throws IOException {
-        final List<PathWithAttributes> selectedForDeletion = callScript();
-        if (selectedForDeletion == null) {
-            LOGGER.trace("Script returned null list (no files to delete)");
-            return true;
-        }
-        deleteSelectedFiles(selectedForDeletion);
-        return true;
-    }
-
-    private List<PathWithAttributes> callScript() throws IOException {
-        final List<PathWithAttributes> sortedPaths = getSortedPaths();
-        trace("Sorted paths:", sortedPaths);
-        final List<PathWithAttributes> result = scriptCondition.selectFilesToDelete(getBasePath(), sortedPaths);
-        return result;
-    }
-
-    private void deleteSelectedFiles(final List<PathWithAttributes> selectedForDeletion) throws IOException {
-        trace("Paths the script selected for deletion:", selectedForDeletion);
-        for (final PathWithAttributes pathWithAttributes : selectedForDeletion) {
-            final Path path = pathWithAttributes == null ? null : pathWithAttributes.getPath();
-            if (isTestMode()) {
-                LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)", path);
-            } else {
-                delete(path);
-            }
-        }
-    }
-
-    /**
-     * Deletes the specified file.
-     * 
-     * @param path the file to delete
-     * @throws IOException if a problem occurred deleting the file
-     */
-    protected void delete(final Path path) throws IOException {
-        LOGGER.trace("Deleting {}", path);
-        Files.deleteIfExists(path);
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute(FileVisitor)
-     */
-    @Override
-    public boolean execute(final FileVisitor<Path> visitor) throws IOException {
-        final List<PathWithAttributes> sortedPaths = getSortedPaths();
-        trace("Sorted paths:", sortedPaths);
-
-        for (PathWithAttributes element : sortedPaths) {
-            try {
-                visitor.visitFile(element.getPath(), element.getAttributes());
-            } catch (final IOException ioex) {
-                LOGGER.error("Error in post-rollover Delete when visiting {}", element.getPath(), ioex);
-                visitor.visitFileFailed(element.getPath(), ioex);
-            }
-        }
-        // TODO return (visitor.success || ignoreProcessingFailure)
-        return true; // do not abort rollover even if processing failed
-    }
-
-    private void trace(final String label, final List<PathWithAttributes> sortedPaths) {
-        LOGGER.trace(label);
-        for (final PathWithAttributes pathWithAttributes : sortedPaths) {
-            LOGGER.trace(pathWithAttributes);
-        }
-    }
-
-    /**
-     * Returns a sorted list of all files up to maxDepth under the basePath.
-     * 
-     * @return a sorted list of files
-     * @throws IOException
-     */
-    List<PathWithAttributes> getSortedPaths() throws IOException {
-        final SortingVisitor sort = new SortingVisitor(pathSorter);
-        super.execute(sort);
-        final List<PathWithAttributes> sortedPaths = sort.getSortedPaths();
-        return sortedPaths;
-    }
-
-    /**
-     * Returns {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise.
-     * 
-     * @return {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise
-     */
-    public boolean isTestMode() {
-        return testMode;
-    }
-
-    @Override
-    protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathCondition> conditions) {
-        return new DeletingVisitor(visitorBaseDir, conditions, testMode);
-    }
-
-    /**
-     * Create a DeleteAction.
-     * 
-     * @param basePath base path from where to start scanning for files to delete.
-     * @param followLinks whether to follow symbolic links. Default is false.
-     * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
-     *            means that only the starting file is visited, unless denied by the security manager. A value of
-     *            MAX_VALUE may be used to indicate that all levels should be visited.
-     * @param testMode if true, files are not deleted but instead a message is printed to the <a
-     *            href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
-     *            at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
-     *            Default is false.
-     * @param PathSorter a plugin implementing the {@link PathSorter} interface
-     * @param PathConditions an array of path conditions (if more than one, they all need to accept a path before it is
-     *            deleted).
-     * @param config The Configuration.
-     * @return A DeleteAction.
-     */
-    @PluginFactory
-    public static DeleteAction createDeleteAction(
-            // @formatter:off
-            @PluginAttribute("basePath") final String basePath, //
-            @PluginAttribute(value = "followLinks", defaultBoolean = false) final boolean followLinks,
-            @PluginAttribute(value = "maxDepth", defaultInt = 1) final int maxDepth,
-            @PluginAttribute(value = "testMode", defaultBoolean = false) final boolean testMode,
-            @PluginElement("PathSorter") final PathSorter sorterParameter,
-            @PluginElement("PathConditions") final PathCondition[] pathConditions,
-            @PluginElement("ScriptCondition") final ScriptCondition scriptCondition,
-            @PluginConfiguration final Configuration config) {
-            // @formatter:on
-        final PathSorter sorter = sorterParameter == null ? new PathSortByModificationTime(true) : sorterParameter;
-        return new DeleteAction(basePath, followLinks, maxDepth, testMode, sorter, pathConditions, scriptCondition,
-                config.getStrSubstitutor());
-    }
-}
+/*
+ * 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.appender.rolling.action;
+
+import java.io.IOException;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.lookup.StrSubstitutor;
+
+/**
+ * Rollover or scheduled action for deleting old log files that are accepted by the specified PathFilters.
+ */
+@Plugin(name = "Delete", category = "Core", printObject = true)
+public class DeleteAction extends AbstractPathAction {
+
+    private final PathSorter pathSorter;
+    private final boolean testMode;
+    private final ScriptCondition scriptCondition;
+
+    /**
+     * Creates a new DeleteAction that starts scanning for files to delete from the specified base path.
+     * 
+     * @param basePath base path from where to start scanning for files to delete.
+     * @param followSymbolicLinks whether to follow symbolic links. Default is false.
+     * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
+     *            means that only the starting file is visited, unless denied by the security manager. A value of
+     *            MAX_VALUE may be used to indicate that all levels should be visited.
+     * @param testMode if true, files are not deleted but instead a message is printed to the <a
+     *            href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
+     *            at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
+     * @param sorter sorts
+     * @param pathConditions an array of path filters (if more than one, they all need to accept a path before it is
+     *            deleted).
+     * @param scriptCondition
+     */
+    DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, final boolean testMode,
+            final PathSorter sorter, final PathCondition[] pathConditions, final ScriptCondition scriptCondition,
+            final StrSubstitutor subst) {
+        super(basePath, followSymbolicLinks, maxDepth, pathConditions, subst);
+        this.testMode = testMode;
+        this.pathSorter = Objects.requireNonNull(sorter, "sorter");
+        this.scriptCondition = scriptCondition;
+        if (scriptCondition == null && (pathConditions == null || pathConditions.length == 0)) {
+            LOGGER.error("Missing Delete conditions: unconditional Delete not supported");
+            throw new IllegalArgumentException("Unconditional Delete not supported");
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute()
+     */
+    @Override
+    public boolean execute() throws IOException {
+        return scriptCondition != null ? executeScript() : super.execute();
+    }
+
+    private boolean executeScript() throws IOException {
+        final List<PathWithAttributes> selectedForDeletion = callScript();
+        if (selectedForDeletion == null) {
+            LOGGER.trace("Script returned null list (no files to delete)");
+            return true;
+        }
+        deleteSelectedFiles(selectedForDeletion);
+        return true;
+    }
+
+    private List<PathWithAttributes> callScript() throws IOException {
+        final List<PathWithAttributes> sortedPaths = getSortedPaths();
+        trace("Sorted paths:", sortedPaths);
+        final List<PathWithAttributes> result = scriptCondition.selectFilesToDelete(getBasePath(), sortedPaths);
+        return result;
+    }
+
+    private void deleteSelectedFiles(final List<PathWithAttributes> selectedForDeletion) throws IOException {
+        trace("Paths the script selected for deletion:", selectedForDeletion);
+        for (final PathWithAttributes pathWithAttributes : selectedForDeletion) {
+            final Path path = pathWithAttributes == null ? null : pathWithAttributes.getPath();
+            if (isTestMode()) {
+                LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)", path);
+            } else {
+                delete(path);
+            }
+        }
+    }
+
+    /**
+     * Deletes the specified file.
+     * 
+     * @param path the file to delete
+     * @throws IOException if a problem occurred deleting the file
+     */
+    protected void delete(final Path path) throws IOException {
+        LOGGER.trace("Deleting {}", path);
+        Files.deleteIfExists(path);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute(FileVisitor)
+     */
+    @Override
+    public boolean execute(final FileVisitor<Path> visitor) throws IOException {
+        final List<PathWithAttributes> sortedPaths = getSortedPaths();
+        trace("Sorted paths:", sortedPaths);
+
+        for (PathWithAttributes element : sortedPaths) {
+            try {
+                visitor.visitFile(element.getPath(), element.getAttributes());
+            } catch (final IOException ioex) {
+                LOGGER.error("Error in post-rollover Delete when visiting {}", element.getPath(), ioex);
+                visitor.visitFileFailed(element.getPath(), ioex);
+            }
+        }
+        // TODO return (visitor.success || ignoreProcessingFailure)
+        return true; // do not abort rollover even if processing failed
+    }
+
+    private void trace(final String label, final List<PathWithAttributes> sortedPaths) {
+        LOGGER.trace(label);
+        for (final PathWithAttributes pathWithAttributes : sortedPaths) {
+            LOGGER.trace(pathWithAttributes);
+        }
+    }
+
+    /**
+     * Returns a sorted list of all files up to maxDepth under the basePath.
+     * 
+     * @return a sorted list of files
+     * @throws IOException
+     */
+    List<PathWithAttributes> getSortedPaths() throws IOException {
+        final SortingVisitor sort = new SortingVisitor(pathSorter);
+        super.execute(sort);
+        final List<PathWithAttributes> sortedPaths = sort.getSortedPaths();
+        return sortedPaths;
+    }
+
+    /**
+     * Returns {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise.
+     * 
+     * @return {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise
+     */
+    public boolean isTestMode() {
+        return testMode;
+    }
+
+    @Override
+    protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathCondition> conditions) {
+        return new DeletingVisitor(visitorBaseDir, conditions, testMode);
+    }
+
+    /**
+     * Create a DeleteAction.
+     * 
+     * @param basePath base path from where to start scanning for files to delete.
+     * @param followLinks whether to follow symbolic links. Default is false.
+     * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
+     *            means that only the starting file is visited, unless denied by the security manager. A value of
+     *            MAX_VALUE may be used to indicate that all levels should be visited.
+     * @param testMode if true, files are not deleted but instead a message is printed to the <a
+     *            href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
+     *            at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
+     *            Default is false.
+     * @param PathSorter a plugin implementing the {@link PathSorter} interface
+     * @param PathConditions an array of path conditions (if more than one, they all need to accept a path before it is
+     *            deleted).
+     * @param config The Configuration.
+     * @return A DeleteAction.
+     */
+    @PluginFactory
+    public static DeleteAction createDeleteAction(
+            // @formatter:off
+            @PluginAttribute("basePath") final String basePath, //
+            @PluginAttribute(value = "followLinks", defaultBoolean = false) final boolean followLinks,
+            @PluginAttribute(value = "maxDepth", defaultInt = 1) final int maxDepth,
+            @PluginAttribute(value = "testMode", defaultBoolean = false) final boolean testMode,
+            @PluginElement("PathSorter") final PathSorter sorterParameter,
+            @PluginElement("PathConditions") final PathCondition[] pathConditions,
+            @PluginElement("ScriptCondition") final ScriptCondition scriptCondition,
+            @PluginConfiguration final Configuration config) {
+            // @formatter:on
+        final PathSorter sorter = sorterParameter == null ? new PathSortByModificationTime(true) : sorterParameter;
+        return new DeleteAction(basePath, followLinks, maxDepth, testMode, sorter, pathConditions, scriptCondition,
+                config.getStrSubstitutor());
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index c062259..26b35d3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -638,9 +638,8 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
         if (event instanceof Log4jLogEvent) {
             event.getThrownProxy(); // ensure ThrowableProxy is initialized
             return new LogEventProxy((Log4jLogEvent) event, includeLocation);
-        } else {
-            return new LogEventProxy(event, includeLocation);
         }
+        return new LogEventProxy(event, includeLocation);
     }
 
     public static Serializable serialize(final Log4jLogEvent event, final boolean includeLocation) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index 788ce73..dfa07d5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -254,12 +254,11 @@ public final class GelfLayout extends AbstractStringLayout {
     static CharSequence formatTimestamp(final long timeMillis) {
         if (timeMillis < 1000) {
             return "0";
-        } else {
-            StringBuilder builder = getTimestampStringBuilder();
-            builder.append(timeMillis);
-            builder.insert(builder.length() - 3, '.');
-            return builder;
         }
+        StringBuilder builder = getTimestampStringBuilder();
+        builder.append(timeMillis);
+        builder.insert(builder.length() - 3, '.');
+        return builder;
     }
 
     private static final ThreadLocal<StringBuilder> timestampStringBuilder = new ThreadLocal<>();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
index b837338..499f0d9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
@@ -175,9 +175,8 @@ public final class DatePatternConverter extends LogEventPatternConverter impleme
         final FixedDateFormat fixedDateFormat = FixedDateFormat.createIfSupported(options);
         if (fixedDateFormat != null) {
             return createFixedFormatter(fixedDateFormat);
-        } else {
-            return createNonFixedFormatter(options);
         }
+        return createNonFixedFormatter(options);
     }
 
     /**


[02/50] logging-log4j2 git commit: LOG4J2-1297 added HdrHistogram dependency for use in latency tests

Posted by mi...@apache.org.
LOG4J2-1297 added HdrHistogram dependency for use in latency tests


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

Branch: refs/heads/LOG4J2-1365
Commit: d9a373f7f0e3b82a1fb9ec908686690c5bcd2b3e
Parents: 08228f2
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 14:33:10 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 14:33:10 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d9a373f7/log4j-core/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index 56eacef..3ce7d8c 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -279,6 +279,11 @@
       <artifactId>java-allocation-instrumenter</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.hdrhistogram</groupId>
+      <artifactId>HdrHistogram</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d9a373f7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c0e54d2..ac79ff5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -736,6 +736,11 @@
         <artifactId>java-allocation-instrumenter</artifactId>
         <version>3.0</version>
       </dependency>
+      <dependency>
+        <groupId>org.hdrhistogram</groupId>
+        <artifactId>HdrHistogram</artifactId>
+        <version>2.1.8</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <build>


[19/50] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent unit test initial version

Posted by mi...@apache.org.
LOG4J2-1334 MutableLogEvent unit test initial version


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

Branch: refs/heads/LOG4J2-1365
Commit: 37066643e99ae35d9689f4ad1ed6d9296dfb9f3a
Parents: aa4ce1e
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 20:43:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 20:43:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/MutableLogEvent.java        |  1 +
 .../log4j/core/impl/MutableLogEventTest.java    | 86 ++++++++++++++++++++
 2 files changed, 87 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/37066643/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 9ca179b..9edb6f2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -66,6 +66,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         this.threadName = event.getThreadName();
         this.threadPriority = event.getThreadPriority();
         this.endOfBatch = event.isEndOfBatch();
+        this.includeLocation = event.isIncludeLocation();
         this.nanoTime = event.getNanoTime();
         setMessage(event.getMessage());
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/37066643/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
new file mode 100644
index 0000000..23a49f4
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java
@@ -0,0 +1,86 @@
+package org.apache.logging.log4j.core.impl;/*
+ * 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.
+ */
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.spi.MutableThreadContextStack;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the MutableLogEvent class.
+ */
+public class MutableLogEventTest {
+    private static final Map<String, String> CONTEXTMAP = createContextMap();
+    private static final ThreadContext.ContextStack STACK = new MutableThreadContextStack(Arrays.asList("abc", "xyz"));
+
+    private static Map<String,String> createContextMap() {
+        Map<String,String> result = new HashMap<>();
+        result.put("a", "1");
+        result.put("b", "2");
+        return result;
+    }
+
+    @Test
+    public void testInitFromCopiesAllFields() {
+//        private ThrowableProxy thrownProxy;
+        Log4jLogEvent source = Log4jLogEvent.newBuilder() //
+                .setContextMap(CONTEXTMAP) //
+                .setContextStack(STACK) //
+                .setEndOfBatch(true) //
+                .setIncludeLocation(true) //
+                .setLevel(Level.FATAL) //
+                .setLoggerFqcn("a.b.c.d.e") //
+                .setLoggerName("my name is Logger") //
+                .setMarker(MarkerManager.getMarker("on your marks")) //
+                .setMessage(new SimpleMessage("msg in a bottle")) //
+                .setNanoTime(1234567) //
+                .setSource(new StackTraceElement("myclass", "mymethod", "myfile", 123)) //
+                .setThreadId(100).setThreadName("threadname").setThreadPriority(10) //
+                .setThrown(new RuntimeException("run")) //
+                .setTimeMillis(987654321)
+                .build();
+        MutableLogEvent mutable = new MutableLogEvent();
+        mutable.initFrom(source);
+        assertEquals("contextMap", CONTEXTMAP, mutable.getContextMap());
+        assertEquals("stack", STACK, mutable.getContextStack());
+        assertEquals("endOfBatch", true, mutable.isEndOfBatch());
+        assertEquals("IncludeLocation()", true, mutable.isIncludeLocation());
+        assertEquals("level", Level.FATAL, mutable.getLevel());
+        assertEquals("LoggerFqcn()", source.getLoggerFqcn(), mutable.getLoggerFqcn());
+        assertEquals("LoggerName", source.getLoggerName(), mutable.getLoggerName());
+        assertEquals("marker", source.getMarker(), mutable.getMarker());
+        assertEquals("msg", source.getMessage(), mutable.getMessage());
+        assertEquals("nano", source.getNanoTime(), mutable.getNanoTime());
+        assertEquals("src", source.getSource(), mutable.getSource());
+        assertEquals("tid", source.getThreadId(), mutable.getThreadId());
+        assertEquals("tname", source.getThreadName(), mutable.getThreadName());
+        assertEquals("tpriority", source.getThreadPriority(), mutable.getThreadPriority());
+        assertEquals("throwns", source.getThrown(), mutable.getThrown());
+        assertEquals("proxy", source.getThrownProxy(), mutable.getThrownProxy());
+        assertEquals("millis", source.getTimeMillis(), mutable.getTimeMillis());
+    }
+}
\ No newline at end of file


[04/50] logging-log4j2 git commit: removed trailing whitespace

Posted by mi...@apache.org.
removed trailing whitespace


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

Branch: refs/heads/LOG4J2-1365
Commit: adcdfc0e219e92177a33c199608584fc6cdfb6ca
Parents: e6d1b97
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 16:37:03 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 16:37:03 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/adcdfc0e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
index 537b634..e59fa53 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
@@ -106,7 +106,7 @@ abstract class JacksonFactory {
     abstract protected String getPropertNameForContextMap();
 
     abstract protected String getPropertNameForSource();
-    
+
     abstract protected String getPropertNameForNanoTime();
 
     abstract protected PrettyPrinter newCompactPrinter();


[45/50] logging-log4j2 git commit: Do not use our own deprecated code.

Posted by mi...@apache.org.
Do not use our own deprecated code.

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

Branch: refs/heads/LOG4J2-1365
Commit: 6b9955df6b67ae4eb7cda187dac50a88760d7eef
Parents: a990c75
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:04:47 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:04:47 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6b9955df/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 eb698ab..574236c 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
@@ -50,7 +50,7 @@ public class LoggerUpdateTest {
     @Test
     public void resetLevel() {
         final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
-        logger.entry();
+        logger.traceEntry();
         List<LogEvent> events = app.getEvents();
         assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
         app.clear();
@@ -62,7 +62,7 @@ public class LoggerUpdateTest {
         */
         loggerConfig.setLevel(Level.DEBUG);
         ctx.updateLoggers();  // This causes all Loggers to refetch information from their LoggerConfig.
-        logger.entry();
+        logger.traceEntry();
         events = app.getEvents();
         assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
     }


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

Posted by mi...@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/98cc7d27
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/98cc7d27
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/98cc7d27

Branch: refs/heads/LOG4J2-1365
Commit: 98cc7d27c6d49da3f81ae6ff8cee2f4b0a4009e5
Parents: 80a4398 3c37ca3
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 15:27:42 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 15:27:42 2016 -0700

----------------------------------------------------------------------
 .../ParameterizedNoReferenceMessageFactory.java |  39 ++++-
 log4j-core/pom.xml                              |   5 +
 .../log4j/core/appender/AsyncAppender.java      |  28 +--
 .../log4j/core/appender/FileManager.java        |   3 +-
 .../core/appender/OutputStreamManager.java      |   7 +-
 .../appender/rolling/RollingFileManager.java    |   4 +-
 .../log4j/core/async/AsyncLoggerConfig.java     |   1 +
 .../core/async/AsyncLoggerConfigDelegate.java   |  10 ++
 .../core/async/AsyncLoggerConfigDisruptor.java  |  66 +++++++-
 .../logging/log4j/core/async/EventRoute.java    |   9 +-
 .../log4j/core/async/RingBufferLogEvent.java    |  15 +-
 .../core/async/ThreadNameCachingStrategy.java   |   4 +-
 .../logging/log4j/core/config/LoggerConfig.java |   5 +-
 .../log4j/core/impl/MutableLogEvent.java        |  46 +++--
 .../core/impl/ReusableLogEventFactory.java      |  34 ++--
 .../log4j/core/jackson/Initializers.java        |   2 +-
 .../core/layout/AbstractJacksonLayout.java      |  17 +-
 .../core/layout/ByteBufferDestination.java      |   8 +-
 .../log4j/core/layout/JacksonFactory.java       |   2 +-
 .../layout/LockingStringBuilderEncoder.java     |   3 +-
 .../log4j/core/layout/StringBuilderEncoder.java |   3 +-
 .../log4j/core/layout/TextEncoderHelper.java    |   1 -
 .../logging/log4j/core/net/SmtpManager.java     |   5 +-
 .../ExtendedThrowablePatternConverter.java      |   5 +-
 .../pattern/RootThrowablePatternConverter.java  |   5 +-
 .../logging/log4j/core/util/Constants.java      |  45 ++++-
 .../core/GcFreeAsynchronousLoggingTest.java     |  41 +++++
 .../logging/log4j/core/GcFreeLoggingTest.java   | 167 ------------------
 .../log4j/core/GcFreeLoggingTestUtil.java       | 169 +++++++++++++++++++
 .../core/GcFreeMixedSyncAyncLoggingTest.java    |  58 +++++++
 .../core/GcFreeSynchronousLoggingTest.java      |  58 +++++++
 .../log4j/core/async/perftest/IdleStrategy.java |  43 +++++
 .../core/async/perftest/NoOpIdleStrategy.java   |  34 ++++
 .../core/async/perftest/SimpleLatencyTest.java  | 118 +++++++++----
 .../log4j/core/impl/MutableLogEventTest.java    |  86 ++++++++++
 .../log4j/test/appender/ListAppender.java       |   9 +-
 .../resources/gcFreeMixedSyncAsyncLogging.xml   |  71 ++++++++
 pom.xml                                         |   5 +
 src/changes/changes.xml                         |   3 +
 39 files changed, 926 insertions(+), 308 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/98cc7d27/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
----------------------------------------------------------------------


[12/50] logging-log4j2 git commit: LOG4J2-1334 RootThrowablePatternConverter bugfix: a long time ago the method getThrownProxy() was added to the LogEvent interface, but RootThrowablePatternConverter still required Log4jLogEvent

Posted by mi...@apache.org.
LOG4J2-1334 RootThrowablePatternConverter bugfix: a long time ago the method getThrownProxy() was added to the LogEvent interface, but RootThrowablePatternConverter still required Log4jLogEvent


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

Branch: refs/heads/LOG4J2-1365
Commit: 380dd467ce795eb5be020db7a969b62284ad326b
Parents: b264c21
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 22:39:02 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 22:39:02 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/pattern/RootThrowablePatternConverter.java       | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/380dd467/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
index e3e7d33..2c75cfc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java
@@ -59,10 +59,7 @@ public final class RootThrowablePatternConverter extends ThrowablePatternConvert
      */
     @Override
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
-        ThrowableProxy proxy = null;
-        if (event instanceof Log4jLogEvent) {
-            proxy = event.getThrownProxy();
-        }
+        ThrowableProxy proxy = event.getThrownProxy();
         final Throwable throwable = event.getThrown();
         if (throwable != null && options.anyLines()) {
             if (proxy == null) {


[46/50] logging-log4j2 git commit: Remove dead comment.

Posted by mi...@apache.org.
Remove dead comment.

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

Branch: refs/heads/LOG4J2-1365
Commit: ce36b37661e45c89c861108b6442eb8249ec2248
Parents: 6b9955d
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:13:17 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:13:17 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/layout/CsvLogEventLayout.java    | 213 +++++++++----------
 1 file changed, 106 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce36b376/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
index ef69f0f..12e0f3d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
@@ -1,107 +1,106 @@
-/*
- * 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.layout;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVPrinter;
-import org.apache.commons.csv.QuoteMode;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-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.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * A Comma-Separated Value (CSV) layout to log events.
- * 
- * Depends on Apache Commons CSV 1.2.
- * 
- * @since 2.4
- */
-@Plugin(name = "CsvLogEventLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
-public class CsvLogEventLayout extends AbstractCsvLayout {
-
-    public static CsvLogEventLayout createDefaultLayout() {
-        return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
-    }
-
-    public static CsvLogEventLayout createLayout(final CSVFormat format) {
-        return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
-    }
-
-    @PluginFactory
-    public static CsvLogEventLayout createLayout(
-            // @formatter:off
-            @PluginConfiguration final Configuration config,
-            @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
-            @PluginAttribute("delimiter") final Character delimiter,
-            @PluginAttribute("escape") final Character escape,
-            @PluginAttribute("quote") final Character quote,
-            @PluginAttribute("quoteMode") final QuoteMode quoteMode,
-            @PluginAttribute("nullString") final String nullString,
-            @PluginAttribute("recordSeparator") final String recordSeparator,
-            @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
-            @PluginAttribute("header") final String header, 
-            @PluginAttribute("footer") final String footer)
-            // @formatter:on
-    {
-
-        final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
-        return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
-    }
-   
-    protected CsvLogEventLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
-        super(config, charset, csvFormat, header, footer);
-    }
-
-    @Override
-    public String toSerializable(final LogEvent event) {
-        final StringBuilder buffer = getStringBuilder();
-        // Revisit when 1.3 is out so that we do not need to create a new
-        // printer for each event.
-        // No need to close the printer.
-        try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
-            printer.print(event.getNanoTime());
-            printer.print(event.getTimeMillis());
-            printer.print(event.getLevel());
-            printer.print(event.getThreadId());
-            printer.print(event.getThreadName());
-            printer.print(event.getThreadPriority());
-            printer.print(event.getMessage().getFormattedMessage());
-            printer.print(event.getLoggerFqcn());
-            printer.print(event.getLoggerName());
-            printer.print(event.getMarker());
-            printer.print(event.getThrownProxy());
-            printer.print(event.getSource());
-            printer.print(event.getContextMap());
-            printer.print(event.getContextStack());
-            printer.println();
-            return buffer.toString();
-        } catch (final IOException e) {
-            StatusLogger.getLogger().error(event.toString(), e);
-            return getFormat().getCommentMarker() + " " + e;
-        }
-    }
-
-}
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.QuoteMode;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+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.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * A Comma-Separated Value (CSV) layout to log events.
+ * 
+ * Depends on Apache Commons CSV 1.2.
+ * 
+ * @since 2.4
+ */
+@Plugin(name = "CsvLogEventLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public class CsvLogEventLayout extends AbstractCsvLayout {
+
+    public static CsvLogEventLayout createDefaultLayout() {
+        return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+    }
+
+    public static CsvLogEventLayout createLayout(final CSVFormat format) {
+        return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
+    }
+
+    @PluginFactory
+    public static CsvLogEventLayout createLayout(
+            // @formatter:off
+            @PluginConfiguration final Configuration config,
+            @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
+            @PluginAttribute("delimiter") final Character delimiter,
+            @PluginAttribute("escape") final Character escape,
+            @PluginAttribute("quote") final Character quote,
+            @PluginAttribute("quoteMode") final QuoteMode quoteMode,
+            @PluginAttribute("nullString") final String nullString,
+            @PluginAttribute("recordSeparator") final String recordSeparator,
+            @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
+            @PluginAttribute("header") final String header, 
+            @PluginAttribute("footer") final String footer)
+            // @formatter:on
+    {
+
+        final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
+        return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
+    }
+   
+    protected CsvLogEventLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+        super(config, charset, csvFormat, header, footer);
+    }
+
+    @Override
+    public String toSerializable(final LogEvent event) {
+        final StringBuilder buffer = getStringBuilder();
+        // Revisit when 1.3 is out so that we do not need to create a new
+        // printer for each event.
+        try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
+            printer.print(event.getNanoTime());
+            printer.print(event.getTimeMillis());
+            printer.print(event.getLevel());
+            printer.print(event.getThreadId());
+            printer.print(event.getThreadName());
+            printer.print(event.getThreadPriority());
+            printer.print(event.getMessage().getFormattedMessage());
+            printer.print(event.getLoggerFqcn());
+            printer.print(event.getLoggerName());
+            printer.print(event.getMarker());
+            printer.print(event.getThrownProxy());
+            printer.print(event.getSource());
+            printer.print(event.getContextMap());
+            printer.print(event.getContextStack());
+            printer.println();
+            return buffer.toString();
+        } catch (final IOException e) {
+            StatusLogger.getLogger().error(event.toString(), e);
+            return getFormat().getCommentMarker() + " " + e;
+        }
+    }
+
+}


[40/50] logging-log4j2 git commit: Unnecessary cast.

Posted by mi...@apache.org.
Unnecessary cast.

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

Branch: refs/heads/LOG4J2-1365
Commit: 9a563a63f80d7daa6c16c19015187d5deb624cf7
Parents: 5f69241
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:53:37 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:53:37 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/appender/RollingRandomAccessFileAppender.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9a563a63/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
index e624985..dc92d7e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
@@ -84,7 +84,7 @@ public final class RollingRandomAccessFileAppender extends AbstractOutputStreamA
      */
     @Override
     public void append(final LogEvent event) {
-        final RollingRandomAccessFileManager manager = (RollingRandomAccessFileManager) getManager();
+        final RollingRandomAccessFileManager manager = getManager();
         manager.checkRollover(event);
 
         // Leverage the nice batching behaviour of async Loggers/Appenders:


[30/50] logging-log4j2 git commit: Add final modifier to private fields.

Posted by mi...@apache.org.
Add final modifier to private 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/4a2ad0c2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4a2ad0c2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4a2ad0c2

Branch: refs/heads/LOG4J2-1365
Commit: 4a2ad0c265a83cc22dde99060f23fcfd6828ce52
Parents: 1494ce2
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:31:51 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:31:51 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/message/ReusableParameterizedMessage.java | 2 +-
 .../org/apache/logging/log4j/core/appender/SocketAppenderTest.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4a2ad0c2/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
index 0c099cf..87cdc1d 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java
@@ -36,7 +36,7 @@ public class ReusableParameterizedMessage implements ReusableMessage {
     private String messagePattern;
     private int argCount;
     private int usedCount;
-    private int[] indices = new int[256];
+    private final int[] indices = new int[256];
     private transient Object[] varargs;
     private transient Object[] params = new Object[10];
     private transient Throwable throwable;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4a2ad0c2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
index 50586f7..9564dd9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
@@ -213,7 +213,7 @@ public class SocketAppenderTest {
         private final DatagramSocket sock;
         private boolean shutdown = false;
         private Thread thread;
-        private CountDownLatch latch = new CountDownLatch(1);
+        private final CountDownLatch latch = new CountDownLatch(1);
 
         public UDPSocketServer() throws IOException {
             this.sock = new DatagramSocket(PORT);


[28/50] logging-log4j2 git commit: Add missing '@Override' annotations to implementations of interface methods.

Posted by mi...@apache.org.
Add missing '@Override' annotations to implementations of interface
methods.

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

Branch: refs/heads/LOG4J2-1365
Commit: 87780643c73606f9d6a43f0ed53cdf3355857597
Parents: 99b5a5d
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:29:28 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:29:28 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/87780643/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
index e5b205c..e6517ed 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
@@ -67,6 +67,7 @@ public class GcFreeLoggingTestUtil {
                 "com/google/monitoring/runtime/instrumentation/Sampler", //
         };
         final Sampler sampler = new Sampler() {
+            @Override
             public void sampleAllocation(int count, String desc, Object newObj, long size) {
                 for (int i = 0; i < exclude.length; i++) {
                     if (exclude[i].equals(desc)) {


[13/50] logging-log4j2 git commit: LOG4J2-1334 make ThreadNameCachingStrategy public so it can be used in ReusableLogEventFactory

Posted by mi...@apache.org.
LOG4J2-1334 make ThreadNameCachingStrategy public so it can be used in ReusableLogEventFactory


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

Branch: refs/heads/LOG4J2-1365
Commit: 2468c8c0e1d55b2181b78abc36fed16a9fd3b61e
Parents: 380dd46
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 14:29:54 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 14:29:54 2016 +0900

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


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2468c8c0/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java
index f82f71c..da39978 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/ThreadNameCachingStrategy.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.util.PropertiesUtil;
 /**
  * Strategy for deciding whether thread name should be cached or not.
  */
-enum ThreadNameCachingStrategy { // LOG4J2-467
+public enum ThreadNameCachingStrategy { // LOG4J2-467
     CACHED {
         @Override
         public String getThreadName() {
@@ -47,7 +47,7 @@ enum ThreadNameCachingStrategy { // LOG4J2-467
 
     abstract String getThreadName();
 
-    static ThreadNameCachingStrategy create() {
+    public static ThreadNameCachingStrategy create() {
         final String name = PropertiesUtil.getProperties().getStringProperty("AsyncLogger.ThreadNameStrategy",
                 CACHED.name());
         try {


[47/50] logging-log4j2 git commit: Remove dead comment.

Posted by mi...@apache.org.
Remove dead comment.

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

Branch: refs/heads/LOG4J2-1365
Commit: a15477ba51bac258238a23cc3fd837cb1a57d1a2
Parents: ce36b37
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:13:36 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:13:36 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/layout/CsvParameterLayout.java   | 207 +++++++++----------
 1 file changed, 103 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a15477ba/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
index 9c792e7..dcae328 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
@@ -1,104 +1,103 @@
-/*
- * 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.layout;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVPrinter;
-import org.apache.commons.csv.QuoteMode;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-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.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * A Comma-Separated Value (CSV) layout to log event parameters.
- * The event message is currently ignored. 
- * 
- * <p>
- * Best used with:
- * </p>
- * <p>
- * {@code logger.debug(new ObjectArrayMessage(1, 2, "Bob"));}
- * </p>
- * 
- * Depends on Apache Commons CSV 1.2.
- * 
- * @since 2.4
- */
-@Plugin(name = "CsvParameterLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
-public class CsvParameterLayout extends AbstractCsvLayout {
-
-    public static AbstractCsvLayout createDefaultLayout() {
-        return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
-    }
-
-    public static AbstractCsvLayout createLayout(final CSVFormat format) {
-        return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
-    }
-
-    @PluginFactory
-    public static AbstractCsvLayout createLayout(
-            // @formatter:off
-            @PluginConfiguration final Configuration config,
-            @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
-            @PluginAttribute("delimiter") final Character delimiter,
-            @PluginAttribute("escape") final Character escape,
-            @PluginAttribute("quote") final Character quote,
-            @PluginAttribute("quoteMode") final QuoteMode quoteMode,
-            @PluginAttribute("nullString") final String nullString,
-            @PluginAttribute("recordSeparator") final String recordSeparator,
-            @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
-            @PluginAttribute("header") final String header, 
-            @PluginAttribute("footer") final String footer)
-            // @formatter:on
-    {
-
-        final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
-        return new CsvParameterLayout(config, charset, csvFormat, header, footer);
-    }
-
-    public CsvParameterLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
-        super(config, charset, csvFormat, header, footer);
-    }
-
-    @Override
-    public String toSerializable(final LogEvent event) {
-        final Message message = event.getMessage();
-        final Object[] parameters = message.getParameters();
-        final StringBuilder buffer = getStringBuilder();
-        // Revisit when 1.3 is out so that we do not need to create a new
-        // printer for each event.
-        // No need to close the printer.
-        try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
-            printer.printRecord(parameters);
-            return buffer.toString();
-        } catch (final IOException e) {
-            StatusLogger.getLogger().error(message, e);
-            return getFormat().getCommentMarker() + " " + e;
-        }
-    }
-
-}
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.QuoteMode;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+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.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * A Comma-Separated Value (CSV) layout to log event parameters.
+ * The event message is currently ignored. 
+ * 
+ * <p>
+ * Best used with:
+ * </p>
+ * <p>
+ * {@code logger.debug(new ObjectArrayMessage(1, 2, "Bob"));}
+ * </p>
+ * 
+ * Depends on Apache Commons CSV 1.2.
+ * 
+ * @since 2.4
+ */
+@Plugin(name = "CsvParameterLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public class CsvParameterLayout extends AbstractCsvLayout {
+
+    public static AbstractCsvLayout createDefaultLayout() {
+        return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+    }
+
+    public static AbstractCsvLayout createLayout(final CSVFormat format) {
+        return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
+    }
+
+    @PluginFactory
+    public static AbstractCsvLayout createLayout(
+            // @formatter:off
+            @PluginConfiguration final Configuration config,
+            @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
+            @PluginAttribute("delimiter") final Character delimiter,
+            @PluginAttribute("escape") final Character escape,
+            @PluginAttribute("quote") final Character quote,
+            @PluginAttribute("quoteMode") final QuoteMode quoteMode,
+            @PluginAttribute("nullString") final String nullString,
+            @PluginAttribute("recordSeparator") final String recordSeparator,
+            @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
+            @PluginAttribute("header") final String header, 
+            @PluginAttribute("footer") final String footer)
+            // @formatter:on
+    {
+
+        final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
+        return new CsvParameterLayout(config, charset, csvFormat, header, footer);
+    }
+
+    public CsvParameterLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+        super(config, charset, csvFormat, header, footer);
+    }
+
+    @Override
+    public String toSerializable(final LogEvent event) {
+        final Message message = event.getMessage();
+        final Object[] parameters = message.getParameters();
+        final StringBuilder buffer = getStringBuilder();
+        // Revisit when 1.3 is out so that we do not need to create a new
+        // printer for each event.
+        try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
+            printer.printRecord(parameters);
+            return buffer.toString();
+        } catch (final IOException e) {
+            StatusLogger.getLogger().error(message, e);
+            return getFormat().getCommentMarker() + " " + e;
+        }
+    }
+
+}


[16/50] logging-log4j2 git commit: LOG4J2-1274 moved CharBuffer size from TextEncoderHelper to Constants, improved Constants docs

Posted by mi...@apache.org.
LOG4J2-1274	moved CharBuffer size from TextEncoderHelper to Constants, improved Constants docs


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

Branch: refs/heads/LOG4J2-1365
Commit: 7a9d18c3e4a31b64633b5a755a4e9bce29d3ba32
Parents: a743e8e
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 14:52:24 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 14:52:24 2016 +0900

----------------------------------------------------------------------
 .../core/layout/LockingStringBuilderEncoder.java  |  3 ++-
 .../log4j/core/layout/StringBuilderEncoder.java   |  3 ++-
 .../log4j/core/layout/TextEncoderHelper.java      |  1 -
 .../apache/logging/log4j/core/util/Constants.java | 18 ++++++++++++++++++
 4 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a9d18c3/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LockingStringBuilderEncoder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LockingStringBuilderEncoder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LockingStringBuilderEncoder.java
index 6224175..e6086c9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LockingStringBuilderEncoder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/LockingStringBuilderEncoder.java
@@ -1,5 +1,6 @@
 package org.apache.logging.log4j.core.layout;
 
+import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.status.StatusLogger;
 
 import java.nio.CharBuffer;
@@ -18,7 +19,7 @@ public class LockingStringBuilderEncoder implements Encoder<StringBuilder> {
     private final CharBuffer cachedCharBuffer;
 
     public LockingStringBuilderEncoder(final Charset charset) {
-        this(charset, TextEncoderHelper.DEFAULT_CHAR_BUFFER_SIZE);
+        this(charset, Constants.ENCODER_CHAR_BUFFER_SIZE);
     }
 
     public LockingStringBuilderEncoder(final Charset charset, final int charBufferSize) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a9d18c3/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/StringBuilderEncoder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/StringBuilderEncoder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/StringBuilderEncoder.java
index 22cb1b5..abb5c96 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/StringBuilderEncoder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/StringBuilderEncoder.java
@@ -1,5 +1,6 @@
 package org.apache.logging.log4j.core.layout;
 
+import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.status.StatusLogger;
 
 import java.nio.ByteBuffer;
@@ -23,7 +24,7 @@ public class StringBuilderEncoder implements Encoder<StringBuilder> {
     private final int byteBufferSize;
 
     public StringBuilderEncoder(final Charset charset) {
-        this(charset, TextEncoderHelper.DEFAULT_CHAR_BUFFER_SIZE, DEFAULT_BYTE_BUFFER_SIZE);
+        this(charset, Constants.ENCODER_CHAR_BUFFER_SIZE, DEFAULT_BYTE_BUFFER_SIZE);
     }
 
     public StringBuilderEncoder(final Charset charset, final int charBufferSize, final int byteBufferSize) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a9d18c3/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
index 09a49d8..7d27830 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
@@ -29,7 +29,6 @@ import java.nio.charset.CoderResult;
  * @since 2.6
  */
 public class TextEncoderHelper {
-    static final int DEFAULT_CHAR_BUFFER_SIZE = 2048;
 
     private TextEncoderHelper() {
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a9d18c3/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index 95bd03e..e1f175b 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -108,15 +108,33 @@ public final class Constants {
 
     /**
      * Initial StringBuilder size used in RingBuffer LogEvents to store the contents of reusable Messages.
+     * <p>
+     * The default value is {@value}, users can override with system property "log4j.initialReusableMsgSize".
+     * </p>
+     * @since 2.6
      */
     public static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
 
     /**
      * Maximum size of the StringBuilders used in RingBuffer LogEvents to store the contents of reusable Messages.
      * After a large message has been delivered to the appenders, the StringBuilder is trimmed to this size.
+     * <p>
+     * The default value is {@value}, which allows the StringBuilder to resize three times from its initial size.
+     * Users can override with system property "log4j.maxReusableMsgSize".
+     * </p>
+     * @since 2.6
      */
     public static final int MAX_REUSABLE_MESSAGE_SIZE = size("log4j.maxReusableMsgSize", (128 * 2 + 2) * 2 + 2);
 
+    /**
+     * Size of CharBuffers used by text encoders.
+     * <p>
+     * The default value is {@value}, users can override with system property "log4j.encoder.charBufferSize".
+     * </p>
+     * @since 2.6
+     */
+    public static final int ENCODER_CHAR_BUFFER_SIZE = size("log4j.encoder.charBufferSize", 2048);
+
     private static int size(final String property, final int defaultValue) {
         return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
     }


[06/50] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name

Posted by mi...@apache.org.
LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name


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

Branch: refs/heads/LOG4J2-1365
Commit: 07cd44a06e4b16d38330d443fc771ada187d537f
Parents: dc9b6af
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:40:29 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:40:29 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/impl/MutableLogEvent.java  | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07cd44a0/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 5330c34..3dce409 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -17,6 +17,7 @@ import java.util.Map;
 
 /**
  * Mutable implementation of the {@code LogEvent} interface.
+ * @since 2.6
  */
 public class MutableLogEvent implements LogEvent, ReusableMessage {
     private static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
@@ -29,18 +30,18 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
     private Level level;
     private String loggerName;
     private Message message;
-    private Throwable thrown;
     private long timeMillis;
+    private Throwable thrown;
+    private ThrowableProxy thrownProxy;
     private Map<String, String> contextMap;
     private ThreadContext.ContextStack contextStack;
     private long threadId;
     private String threadName;
     private int threadPriority;
+    private StackTraceElement source;
     private boolean includeLocation;
     private boolean endOfBatch = false;
     private long nanoTime;
-    private ThrowableProxy thrownProxy;
-    private StackTraceElement source;
     private StringBuilder messageText;
 
     private static int size(final String property, final int defaultValue) {
@@ -87,7 +88,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         source = null;
         contextMap = null;
         contextStack = null;
-        threadName = null;
+        // threadName = null; // THreadName should not be cleared
         // primitive fields that cannot be cleared:
         //timeMillis;
         //threadId;
@@ -143,7 +144,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
 
     public void setMessage(final Message msg) {
         if (msg instanceof ReusableMessage) {
-            ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
+            ((ReusableMessage) msg).formatTo(getMessageTextForWriting()); // init messageText
         } else {
             // if the Message instance is reused, there is no point in freezing its message here
             if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose


[10/50] logging-log4j2 git commit: LOG4J2-1334 SmtpManager must store snapshot of MutableLogEvent in cyclic buffer, not the MutableEvent itself

Posted by mi...@apache.org.
LOG4J2-1334 SmtpManager must store snapshot of MutableLogEvent in cyclic buffer, not the MutableEvent itself


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

Branch: refs/heads/LOG4J2-1365
Commit: e323868b06f16b7f2a117cdc216b688b1cd07e0e
Parents: 328a8bf
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 22:04:22 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 22:04:22 2016 +0900

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/net/SmtpManager.java     | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e323868b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
index b101b2d..ab1d5c7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SmtpManager.java
@@ -43,6 +43,7 @@ import org.apache.logging.log4j.core.appender.AbstractManager;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.core.util.CyclicBuffer;
@@ -83,9 +84,11 @@ public class SmtpManager extends AbstractManager {
         this.buffer = new CyclicBuffer<>(LogEvent.class, data.numElements);
     }
 
-    public void add(final LogEvent event) {
+    public void add(LogEvent event) {
         if (event instanceof Log4jLogEvent && event.getMessage() instanceof ReusableMessage) {
             ((Log4jLogEvent) event).makeMessageImmutable();
+        } else if (event instanceof MutableLogEvent) {
+            event = Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation()));
         }
         buffer.add(event);
     }


[49/50] logging-log4j2 git commit: Merge branch 'master' into LOG4J2-1365

Posted by mi...@apache.org.
Merge branch 'master' into LOG4J2-1365

Conflicts:
	log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java


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

Branch: refs/heads/LOG4J2-1365
Commit: 86f30cfcf1f816f2b491cfab74959049363c7a48
Parents: dae9d79 d3e571f
Author: Mikael Ståldal <mi...@magine.com>
Authored: Mon Apr 18 13:27:17 2016 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Mon Apr 18 13:27:17 2016 +0200

----------------------------------------------------------------------
 .../ParameterizedNoReferenceMessageFactory.java |  39 +-
 .../message/ReusableParameterizedMessage.java   |   2 +-
 .../logging/log4j/message/SimpleMessage.java    |   3 +-
 .../org/apache/logging/log4j/util/Strings.java  |  12 +
 .../org/apache/logging/log4j/util/Unbox.java    |   2 -
 .../log4j/message/ParameterFormatterTest.java   |   2 -
 .../apache/logging/log4j/util/UnboxTest.java    |   2 +
 log4j-core/pom.xml                              |   5 +
 .../log4j/core/appender/AsyncAppender.java      |  28 +-
 .../log4j/core/appender/FileManager.java        |   3 +-
 .../core/appender/MemoryMappedFileManager.java  |   3 +-
 .../core/appender/OutputStreamManager.java      |   7 +-
 .../core/appender/RandomAccessFileManager.java  |   3 +-
 .../RollingRandomAccessFileAppender.java        |   2 +-
 .../core/appender/rolling/PatternProcessor.java |   1 +
 .../appender/rolling/RollingFileManager.java    |   4 +-
 .../rolling/RollingRandomAccessFileManager.java |   3 +-
 .../appender/rolling/action/DeleteAction.java   | 432 +++++-----
 .../core/async/AsyncEventRouterFactory.java     |   2 -
 .../log4j/core/async/AsyncLoggerConfig.java     |   1 +
 .../core/async/AsyncLoggerConfigDelegate.java   |  10 +
 .../core/async/AsyncLoggerConfigDisruptor.java  |  66 +-
 .../logging/log4j/core/async/EventRoute.java    |   9 +-
 .../log4j/core/async/RingBufferLogEvent.java    |  15 +-
 .../core/async/ThreadNameCachingStrategy.java   |   4 +-
 .../logging/log4j/core/config/LoggerConfig.java |   5 +-
 .../logging/log4j/core/impl/Log4jLogEvent.java  |   3 +-
 .../log4j/core/impl/MutableLogEvent.java        |  46 +-
 .../core/impl/ReusableLogEventFactory.java      |  34 +-
 .../log4j/core/jackson/Initializers.java        |   2 +-
 .../log4j/core/jackson/Log4jYamlModule.java     |  48 ++
 .../core/jackson/Log4jYamlObjectMapper.java     |  41 +
 .../core/layout/AbstractJacksonLayout.java      |  17 +-
 .../core/layout/ByteBufferDestination.java      |   8 +-
 .../log4j/core/layout/CsvLogEventLayout.java    | 213 +++--
 .../log4j/core/layout/CsvParameterLayout.java   | 207 +++--
 .../logging/log4j/core/layout/GelfLayout.java   |   9 +-
 .../log4j/core/layout/JacksonFactory.java       |  36 +-
 .../layout/LockingStringBuilderEncoder.java     |   3 +-
 .../log4j/core/layout/StringBuilderEncoder.java |   3 +-
 .../log4j/core/layout/TextEncoderHelper.java    |   1 -
 .../logging/log4j/core/layout/YamlLayout.java   | 824 +++++++++++++++++++
 .../logging/log4j/core/net/SmtpManager.java     |   5 +-
 .../log4j/core/net/server/TcpSocketServer.java  |  19 +-
 .../core/pattern/DatePatternConverter.java      |   3 +-
 .../ExtendedThrowablePatternConverter.java      |   6 +-
 .../pattern/RootThrowablePatternConverter.java  |   6 +-
 .../logging/log4j/core/util/Constants.java      |  45 +-
 .../logging/log4j/MarkerMixInYamlTest.java      |  31 +
 .../log4j/core/AppenderRefLevelJsonTest.java    |  12 +-
 .../log4j/core/AppenderRefLevelTest.java        |  12 +-
 .../core/GcFreeAsynchronousLoggingTest.java     |  41 +
 .../logging/log4j/core/GcFreeLoggingTest.java   | 167 ----
 .../log4j/core/GcFreeLoggingTestUtil.java       | 170 ++++
 .../core/GcFreeMixedSyncAyncLoggingTest.java    |  43 +
 .../core/GcFreeSynchronousLoggingTest.java      |  42 +
 .../apache/logging/log4j/core/LoggerTest.java   |  12 +-
 .../logging/log4j/core/LoggerUpdateTest.java    |   4 +-
 .../logging/log4j/core/PatternSelectorTest.java |  12 +-
 .../logging/log4j/core/StrictXmlConfigTest.java |  13 +-
 .../appender/JsonCompleteFileAppenderTest.java  |   2 +-
 .../log4j/core/appender/SocketAppenderTest.java |   2 +-
 .../log4j/core/async/perftest/IdleStrategy.java |  43 +
 .../core/async/perftest/NoOpIdleStrategy.java   |  34 +
 .../core/async/perftest/SimpleLatencyTest.java  | 119 ++-
 .../core/filter/AbstractScriptFilterTest.java   |   4 +-
 .../log4j/core/impl/MutableLogEventTest.java    |  84 ++
 .../log4j/core/jackson/LevelMixInJsonTest.java  |   1 +
 .../log4j/core/jackson/LevelMixInYamlTest.java  |  29 +
 .../jackson/StackTraceElementMixInTest.java     |   5 +
 .../log4j/core/layout/YamlLayoutTest.java       | 287 +++++++
 .../log4j/test/appender/ListAppender.java       |   9 +-
 .../resources/JsonCompleteFileAppenderTest.xml  |   4 +-
 .../resources/gcFreeMixedSyncAsyncLogging.xml   |  71 ++
 .../appender/NoSqlDatabaseManagerTest.java      |  26 +-
 .../message/ParameterFormatterBenchmark.java    |   2 -
 .../log4j/perf/jmh/CollectionsBenchmark.java    |  12 +-
 .../log4j/perf/jmh/LoggerConfigBenchmark.java   |   2 +-
 .../perf/jmh/TextEncoderHelperBenchmark.java    |   2 +-
 ...ThreadLocalVsConcurrentHashMapBenchmark.java | 186 ++---
 .../logging/log4j/perf/nogc/NoGcLayout.java     |   1 -
 .../logging/log4j/lookup/CustomLookup.java      |   3 +-
 .../logging/log4j/lookup/MapMessageLookup.java  |   6 +-
 .../org/apache/logging/slf4j/LoggerTest.java    | 360 ++++----
 .../log4j/web/ServletRequestThreadContext.java  |  29 +
 pom.xml                                         |   5 +
 src/changes/changes.xml                         |   3 +
 src/site/site.xml                               |   1 +
 src/site/xdoc/manual/layouts.xml.vm             | 151 ++++
 89 files changed, 3193 insertions(+), 1093 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86f30cfc/log4j-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86f30cfc/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --cc log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 9504e8a,6929596..e1e6ab0
--- 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
@@@ -30,12 -33,9 +30,11 @@@ import org.apache.logging.log4j.message
  import org.apache.logging.log4j.message.ReusableMessage;
  import org.apache.logging.log4j.message.SimpleMessage;
  import org.apache.logging.log4j.message.TimestampMessage;
- import org.apache.logging.log4j.util.PropertiesUtil;
  import org.apache.logging.log4j.util.Strings;
  
 -import com.lmax.disruptor.EventFactory;
 +import java.io.IOException;
 +import java.util.HashMap;
 +import java.util.Map;
  
  /**
   * When the Disruptor is started, the RingBuffer is populated with event objects. These objects are then re-used during

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/86f30cfc/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------


[35/50] logging-log4j2 git commit: Remove redundant interfaces.

Posted by mi...@apache.org.
Remove redundant interfaces.

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

Branch: refs/heads/LOG4J2-1365
Commit: b285279a1aa15158da1060a085a6242fe84a2e77
Parents: a6c32c5
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:41:07 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:41:07 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/appender/MemoryMappedFileManager.java       | 2 +-
 .../logging/log4j/core/appender/RandomAccessFileManager.java       | 2 +-
 .../core/appender/rolling/RollingRandomAccessFileManager.java      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b285279a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index 336b9ee..1986993 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -56,7 +56,7 @@ import org.apache.logging.log4j.core.util.NullOutputStream;
  * @since 2.1
  */
 //CHECKSTYLE:ON
-public class MemoryMappedFileManager extends OutputStreamManager implements ByteBufferDestination {
+public class MemoryMappedFileManager extends OutputStreamManager {
     /**
      * Default length of region to map.
      */

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b285279a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
index 6a2bee5..674c25f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
@@ -34,7 +34,7 @@ import org.apache.logging.log4j.core.util.NullOutputStream;
  * this class uses a {@code ByteBuffer} and a {@code RandomAccessFile} to do the
  * I/O.
  */
-public class RandomAccessFileManager extends OutputStreamManager implements ByteBufferDestination {
+public class RandomAccessFileManager extends OutputStreamManager {
     static final int DEFAULT_BUFFER_SIZE = 256 * 1024;
 
     private static final RandomAccessFileManagerFactory FACTORY = new RandomAccessFileManagerFactory();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b285279a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index 39f30be..e76dba6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -33,7 +33,7 @@ import org.apache.logging.log4j.core.util.NullOutputStream;
  * Extends RollingFileManager but instead of using a buffered output stream, this class uses a {@code ByteBuffer} and a
  * {@code RandomAccessFile} to do the I/O.
  */
-public class RollingRandomAccessFileManager extends RollingFileManager implements ByteBufferDestination {
+public class RollingRandomAccessFileManager extends RollingFileManager {
     /**
      * The default buffer size.
      */


[26/50] logging-log4j2 git commit: [LOG4J2-1362] Create a YAML layout.

Posted by mi...@apache.org.
[LOG4J2-1362] Create a YAML 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/ffbd8c9b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ffbd8c9b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ffbd8c9b

Branch: refs/heads/LOG4J2-1365
Commit: ffbd8c9b2268815449b3b5321cdbf936395d34f1
Parents: 5114233
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:07:40 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:07:40 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/layout/YamlLayout.java   | 677 ++++++++++++++++++-
 .../appender/JsonCompleteFileAppenderTest.java  |   2 +-
 src/site/site.xml                               |   1 +
 src/site/xdoc/manual/layouts.xml.vm             | 151 +++++
 4 files changed, 807 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffbd8c9b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
index 0426fea..b68b836 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
@@ -32,27 +32,664 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.util.Strings;
 
 /**
  * Appends a series of YAML events as strings serialized as bytes.
  *
- * <h3>Complete well-formed YAML vs. fragment YAML</h3>
  * <p>
- * If you configure {@code complete="true"}, the appender outputs a well-formed YAML document. By default, with
- * {@code complete="false"}, you should include the output as an <em>external file</em> in a separate file to form a
- * well-formed YAML document.
- * </p>
- * <p>
- * A well-formed YAML event follows this pattern:
+ * A YAML log event follows this pattern:
  * </p>
  *
- * <pre>
- * 
- * </pre>
- * <p>
- * If {@code complete="false"}, the appender does not write the YAML open array character "[" at the start of the
- * document, "]" and the end, nor comma "," between records.
- * </p>
+ * <pre>---
+timeMillis: 1
+thread: "MyThreadName"
+level: "DEBUG"
+loggerName: "a.B"
+marker:
+  name: "Marker1"
+  parents:
+  - name: "ParentMarker1"
+    parents:
+    - name: "GrandMotherMarker"
+    - name: "GrandFatherMarker"
+  - name: "ParentMarker2"
+message: "Msg"
+thrown:
+  commonElementCount: 0
+  localizedMessage: "testIOEx"
+  message: "testIOEx"
+  name: "java.io.IOException"
+  cause:
+    commonElementCount: 27
+    localizedMessage: "testNPEx"
+    message: "testNPEx"
+    name: "java.lang.NullPointerException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 52
+      exact: false
+      location: "test-classes/"
+      version: "?"
+  extendedStackTrace:
+  - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+    method: "createLogEvent"
+    file: "LogEventFixtures.java"
+    line: 55
+    exact: true
+    location: "test-classes/"
+    version: "?"
+  - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+    method: "testAllFeatures"
+    file: "YamlLayoutTest.java"
+    line: 109
+    exact: true
+    location: "test-classes/"
+    version: "?"
+  - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+    method: "testLocationOnCompactOffEventEolOffMdcOn"
+    file: "YamlLayoutTest.java"
+    line: 280
+    exact: true
+    location: "test-classes/"
+    version: "?"
+  - class: "sun.reflect.NativeMethodAccessorImpl"
+    method: "invoke0"
+    file: "NativeMethodAccessorImpl.java"
+    line: -2
+    exact: false
+    location: "?"
+    version: "1.7.0_79"
+  - class: "sun.reflect.NativeMethodAccessorImpl"
+    method: "invoke"
+    file: "NativeMethodAccessorImpl.java"
+    line: 57
+    exact: false
+    location: "?"
+    version: "1.7.0_79"
+  - class: "sun.reflect.DelegatingMethodAccessorImpl"
+    method: "invoke"
+    file: "DelegatingMethodAccessorImpl.java"
+    line: 43
+    exact: false
+    location: "?"
+    version: "1.7.0_79"
+  - class: "java.lang.reflect.Method"
+    method: "invoke"
+    file: "Method.java"
+    line: 606
+    exact: false
+    location: "?"
+    version: "1.7.0_79"
+  - class: "org.junit.runners.model.FrameworkMethod$1"
+    method: "runReflectiveCall"
+    file: "FrameworkMethod.java"
+    line: 50
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.internal.runners.model.ReflectiveCallable"
+    method: "run"
+    file: "ReflectiveCallable.java"
+    line: 12
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.model.FrameworkMethod"
+    method: "invokeExplosively"
+    file: "FrameworkMethod.java"
+    line: 47
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.internal.runners.statements.InvokeMethod"
+    method: "evaluate"
+    file: "InvokeMethod.java"
+    line: 17
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner"
+    method: "runLeaf"
+    file: "ParentRunner.java"
+    line: 325
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.BlockJUnit4ClassRunner"
+    method: "runChild"
+    file: "BlockJUnit4ClassRunner.java"
+    line: 78
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.BlockJUnit4ClassRunner"
+    method: "runChild"
+    file: "BlockJUnit4ClassRunner.java"
+    line: 57
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner$3"
+    method: "run"
+    file: "ParentRunner.java"
+    line: 290
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner$1"
+    method: "schedule"
+    file: "ParentRunner.java"
+    line: 71
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner"
+    method: "runChildren"
+    file: "ParentRunner.java"
+    line: 288
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner"
+    method: "access$000"
+    file: "ParentRunner.java"
+    line: 58
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner$2"
+    method: "evaluate"
+    file: "ParentRunner.java"
+    line: 268
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.internal.runners.statements.RunBefores"
+    method: "evaluate"
+    file: "RunBefores.java"
+    line: 26
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.internal.runners.statements.RunAfters"
+    method: "evaluate"
+    file: "RunAfters.java"
+    line: 27
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.junit.runners.ParentRunner"
+    method: "run"
+    file: "ParentRunner.java"
+    line: 363
+    exact: true
+    location: "junit-4.12.jar"
+    version: "4.12"
+  - class: "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference"
+    method: "run"
+    file: "JUnit4TestReference.java"
+    line: 86
+    exact: true
+    location: ".cp/"
+    version: "?"
+  - class: "org.eclipse.jdt.internal.junit.runner.TestExecution"
+    method: "run"
+    file: "TestExecution.java"
+    line: 38
+    exact: true
+    location: ".cp/"
+    version: "?"
+  - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+    method: "runTests"
+    file: "RemoteTestRunner.java"
+    line: 459
+    exact: true
+    location: ".cp/"
+    version: "?"
+  - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+    method: "runTests"
+    file: "RemoteTestRunner.java"
+    line: 675
+    exact: true
+    location: ".cp/"
+    version: "?"
+  - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+    method: "run"
+    file: "RemoteTestRunner.java"
+    line: 382
+    exact: true
+    location: ".cp/"
+    version: "?"
+  - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+    method: "main"
+    file: "RemoteTestRunner.java"
+    line: 192
+    exact: true
+    location: ".cp/"
+    version: "?"
+  suppressed:
+  - commonElementCount: 0
+    localizedMessage: "I am suppressed exception 1"
+    message: "I am suppressed exception 1"
+    name: "java.lang.IndexOutOfBoundsException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 56
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testAllFeatures"
+      file: "YamlLayoutTest.java"
+      line: 109
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testLocationOnCompactOffEventEolOffMdcOn"
+      file: "YamlLayoutTest.java"
+      line: 280
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "sun.reflect.NativeMethodAccessorImpl"
+      method: "invoke0"
+      file: "NativeMethodAccessorImpl.java"
+      line: -2
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "sun.reflect.NativeMethodAccessorImpl"
+      method: "invoke"
+      file: "NativeMethodAccessorImpl.java"
+      line: 57
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "sun.reflect.DelegatingMethodAccessorImpl"
+      method: "invoke"
+      file: "DelegatingMethodAccessorImpl.java"
+      line: 43
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "java.lang.reflect.Method"
+      method: "invoke"
+      file: "Method.java"
+      line: 606
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "org.junit.runners.model.FrameworkMethod$1"
+      method: "runReflectiveCall"
+      file: "FrameworkMethod.java"
+      line: 50
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.model.ReflectiveCallable"
+      method: "run"
+      file: "ReflectiveCallable.java"
+      line: 12
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.model.FrameworkMethod"
+      method: "invokeExplosively"
+      file: "FrameworkMethod.java"
+      line: 47
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.InvokeMethod"
+      method: "evaluate"
+      file: "InvokeMethod.java"
+      line: 17
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "runLeaf"
+      file: "ParentRunner.java"
+      line: 325
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.BlockJUnit4ClassRunner"
+      method: "runChild"
+      file: "BlockJUnit4ClassRunner.java"
+      line: 78
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.BlockJUnit4ClassRunner"
+      method: "runChild"
+      file: "BlockJUnit4ClassRunner.java"
+      line: 57
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$3"
+      method: "run"
+      file: "ParentRunner.java"
+      line: 290
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$1"
+      method: "schedule"
+      file: "ParentRunner.java"
+      line: 71
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "runChildren"
+      file: "ParentRunner.java"
+      line: 288
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "access$000"
+      file: "ParentRunner.java"
+      line: 58
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$2"
+      method: "evaluate"
+      file: "ParentRunner.java"
+      line: 268
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.RunBefores"
+      method: "evaluate"
+      file: "RunBefores.java"
+      line: 26
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.RunAfters"
+      method: "evaluate"
+      file: "RunAfters.java"
+      line: 27
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "run"
+      file: "ParentRunner.java"
+      line: 363
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference"
+      method: "run"
+      file: "JUnit4TestReference.java"
+      line: 86
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.TestExecution"
+      method: "run"
+      file: "TestExecution.java"
+      line: 38
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "runTests"
+      file: "RemoteTestRunner.java"
+      line: 459
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "runTests"
+      file: "RemoteTestRunner.java"
+      line: 675
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "run"
+      file: "RemoteTestRunner.java"
+      line: 382
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "main"
+      file: "RemoteTestRunner.java"
+      line: 192
+      exact: true
+      location: ".cp/"
+      version: "?"
+  - commonElementCount: 0
+    localizedMessage: "I am suppressed exception 2"
+    message: "I am suppressed exception 2"
+    name: "java.lang.IndexOutOfBoundsException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 57
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testAllFeatures"
+      file: "YamlLayoutTest.java"
+      line: 109
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testLocationOnCompactOffEventEolOffMdcOn"
+      file: "YamlLayoutTest.java"
+      line: 280
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "sun.reflect.NativeMethodAccessorImpl"
+      method: "invoke0"
+      file: "NativeMethodAccessorImpl.java"
+      line: -2
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "sun.reflect.NativeMethodAccessorImpl"
+      method: "invoke"
+      file: "NativeMethodAccessorImpl.java"
+      line: 57
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "sun.reflect.DelegatingMethodAccessorImpl"
+      method: "invoke"
+      file: "DelegatingMethodAccessorImpl.java"
+      line: 43
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "java.lang.reflect.Method"
+      method: "invoke"
+      file: "Method.java"
+      line: 606
+      exact: false
+      location: "?"
+      version: "1.7.0_79"
+    - class: "org.junit.runners.model.FrameworkMethod$1"
+      method: "runReflectiveCall"
+      file: "FrameworkMethod.java"
+      line: 50
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.model.ReflectiveCallable"
+      method: "run"
+      file: "ReflectiveCallable.java"
+      line: 12
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.model.FrameworkMethod"
+      method: "invokeExplosively"
+      file: "FrameworkMethod.java"
+      line: 47
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.InvokeMethod"
+      method: "evaluate"
+      file: "InvokeMethod.java"
+      line: 17
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "runLeaf"
+      file: "ParentRunner.java"
+      line: 325
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.BlockJUnit4ClassRunner"
+      method: "runChild"
+      file: "BlockJUnit4ClassRunner.java"
+      line: 78
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.BlockJUnit4ClassRunner"
+      method: "runChild"
+      file: "BlockJUnit4ClassRunner.java"
+      line: 57
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$3"
+      method: "run"
+      file: "ParentRunner.java"
+      line: 290
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$1"
+      method: "schedule"
+      file: "ParentRunner.java"
+      line: 71
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "runChildren"
+      file: "ParentRunner.java"
+      line: 288
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "access$000"
+      file: "ParentRunner.java"
+      line: 58
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner$2"
+      method: "evaluate"
+      file: "ParentRunner.java"
+      line: 268
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.RunBefores"
+      method: "evaluate"
+      file: "RunBefores.java"
+      line: 26
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.internal.runners.statements.RunAfters"
+      method: "evaluate"
+      file: "RunAfters.java"
+      line: 27
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.junit.runners.ParentRunner"
+      method: "run"
+      file: "ParentRunner.java"
+      line: 363
+      exact: true
+      location: "junit-4.12.jar"
+      version: "4.12"
+    - class: "org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference"
+      method: "run"
+      file: "JUnit4TestReference.java"
+      line: 86
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.TestExecution"
+      method: "run"
+      file: "TestExecution.java"
+      line: 38
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "runTests"
+      file: "RemoteTestRunner.java"
+      line: 459
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "runTests"
+      file: "RemoteTestRunner.java"
+      line: 675
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "run"
+      file: "RemoteTestRunner.java"
+      line: 382
+      exact: true
+      location: ".cp/"
+      version: "?"
+    - class: "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"
+      method: "main"
+      file: "RemoteTestRunner.java"
+      line: 192
+      exact: true
+      location: ".cp/"
+      version: "?"
+contextStack:
+- "stack_msg1"
+- "stack_msg2"
+endOfBatch: false
+loggerFqcn: "f.q.c.n"
+contextMap:
+- key: "MDC.B"
+  value: "B_Value"
+- key: "MDC.A"
+  value: "A_Value"
+threadId: 1
+threadPriority: 5
+source:
+  class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+  method: "createLogEvent"
+  file: "LogEventFixtures.java"
+  line: 53</pre>
  * <p>
  * This approach enforces the independence of the YamlLayout and the appender where you embed it.
  * </p>
@@ -61,19 +698,13 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory;
  * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
  * events containing non ASCII characters could result in corrupted log files.
  * </p>
- * <h3>Pretty vs. compact YAML</h3>
- * <p>
- * By default, the YAML layout is not compact (a.k.a. "pretty") with {@code compact="false"}, which means the appender
- * uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no end-of-line or
- * indentation is used. Message content may contain, of course, escaped end-of-lines.
- * </p>
  */
-@Plugin(name = "JsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+@Plugin(name = "YamlLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
 public final class YamlLayout extends AbstractJacksonLayout {
 
-    private static final String DEFAULT_FOOTER = ""; // TODO maybe
+    private static final String DEFAULT_FOOTER = Strings.EMPTY;
 
-    private static final String DEFAULT_HEADER = ""; // TODO maybe
+    private static final String DEFAULT_HEADER = Strings.EMPTY;
 
     static final String CONTENT_TYPE = "application/yaml";
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffbd8c9b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
index 6634fde..d8355a3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/JsonCompleteFileAppenderTest.java
@@ -30,7 +30,7 @@ import org.junit.rules.RuleChain;
 import static org.junit.Assert.*;
 
 /**
- * Tests a "complete" XML file a.k.a. a well-formed XML file.
+ * Tests a "complete" JSON file.
  */
 public class JsonCompleteFileAppenderTest {
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffbd8c9b/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index 71819c2..b7f7a35 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -140,6 +140,7 @@
         <item name="Serialized" href="/manual/layouts.html#SerializedLayout"/>
         <item name="Syslog" href="/manual/layouts.html#SyslogLayout"/>
         <item name="XML" href="/manual/layouts.html#XMLLayout"/>
+        <item name="YAML" href="/manual/layouts.html#YamlLayout"/>
         <item name="Location Information" href="/manual/layouts.html#LocationInformation"/>
       </item>
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ffbd8c9b/src/site/xdoc/manual/layouts.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/layouts.xml.vm b/src/site/xdoc/manual/layouts.xml.vm
index 31ac6bd..ae4c1a0 100644
--- a/src/site/xdoc/manual/layouts.xml.vm
+++ b/src/site/xdoc/manual/layouts.xml.vm
@@ -1811,6 +1811,157 @@ at org.apache.logging.log4j.core.pattern.ExtendedThrowableTest.testException(Ext
           of course, end-of-lines.
           </p>
         </subsection>
+        <a name="YamlLayout"/>
+        <subsection name="YamlLayout">
+          <!-- From Javadoc of org.apache.logging.log4j.core.layout.YamlLayout -->
+          <p>
+            Appends a series of YAML events as strings serialized as bytes.
+          </p>
+          <p>
+            A YAML log event follows this pattern:
+          </p>
+          <pre>---
+timeMillis: 1
+thread: "MyThreadName"
+level: "DEBUG"
+loggerName: "a.B"
+marker:
+  name: "Marker1"
+  parents:
+  - name: "ParentMarker1"
+    parents:
+    - name: "GrandMotherMarker"
+    - name: "GrandFatherMarker"
+  - name: "ParentMarker2"
+message: "Msg"
+thrown:
+  commonElementCount: 0
+  localizedMessage: "testIOEx"
+  message: "testIOEx"
+  name: "java.io.IOException"
+  cause:
+    commonElementCount: 27
+    localizedMessage: "testNPEx"
+    message: "testNPEx"
+    name: "java.lang.NullPointerException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 52
+      exact: false
+      location: "test-classes/"
+      version: "?"
+  extendedStackTrace:
+  - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+    method: "createLogEvent"
+    file: "LogEventFixtures.java"
+    line: 55
+    exact: true
+    location: "test-classes/"
+    version: "?"
+  - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+    method: "testAllFeatures"
+    file: "YamlLayoutTest.java"
+    line: 109
+    exact: true
+    location: "test-classes/"
+    version: "?"
+  - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+    method: "testLocationOnCompactOffEventEolOffMdcOn"
+    file: "YamlLayoutTest.java"
+    line: 280
+    exact: true
+    location: "test-classes/"
+    version: "?"
+
+...
+
+  suppressed:
+  - commonElementCount: 0
+    localizedMessage: "I am suppressed exception 1"
+    message: "I am suppressed exception 1"
+    name: "java.lang.IndexOutOfBoundsException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 56
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testAllFeatures"
+      file: "YamlLayoutTest.java"
+      line: 109
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testLocationOnCompactOffEventEolOffMdcOn"
+      file: "YamlLayoutTest.java"
+      line: 280
+      exact: true
+      location: "test-classes/"
+      version: "?"
+
+...
+
+  - commonElementCount: 0
+    localizedMessage: "I am suppressed exception 2"
+    message: "I am suppressed exception 2"
+    name: "java.lang.IndexOutOfBoundsException"
+    extendedStackTrace:
+    - class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+      method: "createLogEvent"
+      file: "LogEventFixtures.java"
+      line: 57
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testAllFeatures"
+      file: "YamlLayoutTest.java"
+      line: 109
+      exact: true
+      location: "test-classes/"
+      version: "?"
+    - class: "org.apache.logging.log4j.core.layout.YamlLayoutTest"
+      method: "testLocationOnCompactOffEventEolOffMdcOn"
+      file: "YamlLayoutTest.java"
+      line: 280
+      exact: true
+      location: "test-classes/"
+      version: "?"
+
+...
+
+contextStack:
+- "stack_msg1"
+- "stack_msg2"
+endOfBatch: false
+loggerFqcn: "f.q.c.n"
+contextMap:
+- key: "MDC.B"
+  value: "B_Value"
+- key: "MDC.A"
+  value: "A_Value"
+threadId: 1
+threadPriority: 5
+source:
+  class: "org.apache.logging.log4j.core.layout.LogEventFixtures"
+  method: "createLogEvent"
+  file: "LogEventFixtures.java"
+  line: 53</pre>
+        <p>
+          This approach enforces the independence of the YamlLayout and the appender where you embed it.
+        </p>
+        <h4>Encoding</h4>
+        <p>
+          Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
+          events containing non ASCII characters could result in corrupted log files.
+        </p>
+        </subsection>
         <a name="LocationInformation"/>
         <subsection name="Location Information">
         <p>


[21/50] logging-log4j2 git commit: LOG4J2-1297 made some progress on latency test

Posted by mi...@apache.org.
LOG4J2-1297 made some progress on latency test


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

Branch: refs/heads/LOG4J2-1365
Commit: c5f5cc9f2079235ac36c050bbc42bf3ac28edc28
Parents: 8ebed8f
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 22:19:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 22:19:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/async/perftest/IdleStrategy.java | 43 ++++++++++
 .../core/async/perftest/NoOpIdleStrategy.java   | 34 ++++++++
 .../core/async/perftest/SimpleLatencyTest.java  | 87 +++++++++++++-------
 3 files changed, 133 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5f5cc9f/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/IdleStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/IdleStrategy.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/IdleStrategy.java
new file mode 100644
index 0000000..77d9d74
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/IdleStrategy.java
@@ -0,0 +1,43 @@
+package org.apache.logging.log4j.core.async.perftest;
+
+/**
+ * Idle strategy for use by threads when they do not have work to do.
+ *
+ * <h3>Note regarding implementor state</h3>
+ *
+ * Some implementations are known to be stateful, please note that you cannot safely assume implementations to be stateless.
+ * Where implementations are stateful it is recommended that implementation state is padded to avoid false sharing.
+ *
+ * <h3>Note regarding potential for TTSP(Time To Safe Point) issues</h3>
+ *
+ * If the caller spins in a 'counted' loop, and the implementation does not include a a safepoint poll this may cause a TTSP
+ * (Time To SafePoint) problem. If this is the case for your application you can solve it by preventing the idle method from
+ * being inlined by using a Hotspot compiler command as a JVM argument e.g:
+ * <code>-XX:CompileCommand=dontinline,org.apache.logging.log4j.core.async.perftest.NoOpIdleStrategy::idle</code>
+ *
+ * @see <a href="https://github.com/real-logic/Agrona/blob/master/src/main/java/org/agrona/concurrent/IdleStrategy.java">
+ *     https://github.com/real-logic/Agrona/blob/master/src/main/java/org/agrona/concurrent/IdleStrategy.java</a>
+ */
+public interface IdleStrategy {
+    /**
+     * Perform current idle action (e.g. nothing/yield/sleep). To be used in conjunction with {@link IdleStrategy#reset()}
+     * to clear internal state when idle period is over (or before it begins). Callers are expected to follow this pattern:
+     *
+     * <pre>
+     * <code>while (isRunning) {
+     *   if (!hasWork()) {
+     *     idleStrategy.reset();
+     *     while (!hasWork()) {
+     *       if (!isRunning) {
+     *         return;
+     *       }
+     *       idleStrategy.idle();
+     *     }
+     *   }
+     *   doWork();
+     * }
+     * </code>
+     * </pre>
+     */
+    void idle();
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5f5cc9f/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/NoOpIdleStrategy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/NoOpIdleStrategy.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/NoOpIdleStrategy.java
new file mode 100644
index 0000000..867a9dd
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/NoOpIdleStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * 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.async.perftest;
+
+/**
+ * Low-latency idle strategy to be employed in loops that do significant work on each iteration such that any work in the
+ * idle strategy would be wasteful.
+ */
+public class NoOpIdleStrategy implements IdleStrategy {
+
+    /**
+     * <b>Note</b>: this implementation will result in no safepoint poll once inlined.
+     *
+     * @see IdleStrategy
+     */
+    @Override
+    public void idle() {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5f5cc9f/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
index 93b3621..f7459b6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimpleLatencyTest.java
@@ -16,15 +16,14 @@
  */
 package org.apache.logging.log4j.core.async.perftest;
 
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import com.lmax.disruptor.collections.Histogram;
+import org.HdrHistogram.Histogram;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.async.AsyncLogger;
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
 
 /**
  *
@@ -33,31 +32,38 @@ public class SimpleLatencyTest {
     private static final String LATENCY_MSG = new String(new char[64]);
 
     public static void main(String[] args) throws Exception {
-        System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
-        System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
-        System.setProperty("log4j2.enable.threadlocals", "true");
-        System.setProperty("AsyncLogger.WaitStrategy", "Block");
+        //System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
+        //System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
 
         Logger logger = LogManager.getLogger();
-        if (!(logger instanceof AsyncLogger)) {
-            throw new IllegalStateException();
-        }
-        logger.info("Starting...");
+        logger.info("Starting..."); // initializes Log4j
         Thread.sleep(100);
 
-        System.out.println(PerfTest.calcNanoTimeCost());
         final long nanoTimeCost = PerfTest.calcNanoTimeCost();
-        final Histogram warmupHistogram = PerfTest.createHistogram();
-        final Histogram histogram = PerfTest.createHistogram();
+        System.out.println(nanoTimeCost);
+
+        long maxThroughput = 1000 * 1000; // just assume... TODO make parameter
+        double targetLoadLevel = 0.02; // TODO make parameter
+
+        long targetMsgPerSec = (long) (maxThroughput * targetLoadLevel);
+        long targetMsgCountPerIteration = 5 * 1000 * 1000;
+        long durationMillisPerIteration = (1000 * targetMsgCountPerIteration) / targetMsgPerSec;
+
+
         final int threadCount = 1;
+        List<Histogram> warmupHistograms = new ArrayList<>(threadCount);
 
         final int WARMUP_COUNT = 500000;
-        runLatencyTest(logger, WARMUP_COUNT, warmupHistogram, nanoTimeCost, threadCount);
+        final long interval = -1; // TODO calculate
+        final IdleStrategy idleStrategy = new NoOpIdleStrategy();
+        runLatencyTest(logger, WARMUP_COUNT, interval, idleStrategy, warmupHistograms, nanoTimeCost, threadCount);
         Thread.sleep(1000);
 
+        List<Histogram> histograms = new ArrayList<>(threadCount);
+
         for (int i = 0 ; i < 30; i++) {
             final int ITERATIONS = 100 * 1000;// * 30;
-            runLatencyTest(logger, ITERATIONS, histogram, nanoTimeCost, threadCount);
+            runLatencyTest(logger, ITERATIONS, interval, idleStrategy, histograms, nanoTimeCost, threadCount);
 
             // wait 10 microsec
             final long PAUSE_NANOS = 1000000 * threadCount;
@@ -66,22 +72,41 @@ public class SimpleLatencyTest {
                 // busy spin
                 Thread.yield();
             }
-
         }
-
-        System.out.println(histogram);
     }
 
-    public static void runLatencyTest(final Logger logger, final int samples, final Histogram histogram,
-            final long nanoTimeCost, final int threadCount) {
-        for (int i = 0; i < samples; i++) {
-            final long s1 = System.nanoTime();
-            logger.info(LATENCY_MSG);
-            final long s2 = System.nanoTime();
-            final long value = s2 - s1 - nanoTimeCost;
-            if (value > 0) {
-                histogram.addObservation(value);
-            }
+    public static void runLatencyTest(final Logger logger, final int samples, final long interval,
+            final IdleStrategy idleStrategy, final List<Histogram> histograms, final long nanoTimeCost,
+            final int threadCount) {
+
+        final CountDownLatch LATCH = new CountDownLatch(threadCount);
+        for (int i = 0; i < threadCount; i++) {
+            final Histogram hist = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
+            histograms.add(hist);
+            final Thread t = new Thread("latencytest-" + i) {
+                public void run() {
+                    LATCH.countDown();
+                    try {
+                        LATCH.await();
+                    } catch (InterruptedException e) {
+                        interrupt(); // restore interrupt status
+                        return;
+                    }
+                    for (int i = 0; i < samples; i++) {
+                        final long s1 = System.nanoTime();
+                        logger.info(LATENCY_MSG);
+                        final long s2 = System.nanoTime();
+                        final long value = s2 - s1 - nanoTimeCost;
+                        if (value > 0) {
+                            hist.recordValueWithExpectedInterval(value, interval);
+                        }
+                        while (System.nanoTime() - s2 < interval) {
+                            idleStrategy.idle();
+                        }
+                    }
+                }
+            };
+            t.start();
         }
     }
 }


[07/50] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by mi...@apache.org.
LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)


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

Branch: refs/heads/LOG4J2-1365
Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
Parents: 07cd44a
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:41:40 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:41:40 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
index 97ca15d..19aeaee 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
@@ -31,6 +31,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.layout.SerializedLayout;
 
 /**
@@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
     public synchronized void append(final LogEvent event) {
         final Layout<? extends Serializable> layout = getLayout();
         if (layout == null) {
-            events.add(event);
+            if (event instanceof MutableLogEvent) {
+                // must take snapshot or subsequent calls to logger.log() will modify this event
+                events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation())));
+            } else {
+                events.add(event);
+            }
         } else if (layout instanceof SerializedLayout) {
             final byte[] header = layout.getHeader();
             final byte[] content = layout.toByteArray(event);


[08/50] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

Posted by mi...@apache.org.
LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.


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

Branch: refs/heads/LOG4J2-1365
Commit: cedf155230553d8c31bc669e3597b266dc3bf709
Parents: 3f395f6
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:49:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:49:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index 7cbc798..22e2d36 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -22,6 +22,8 @@ import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.util.StringBuilderWriter;
 import org.apache.logging.log4j.util.Strings;
 
@@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
 
     /**
      * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
-     * 
+     *
      * @param event The LogEvent.
      * @return The XML representation of the LogEvent.
      */
     @Override
     public String toSerializable(final LogEvent event) {
-        final StringBuilderWriter writer = new StringBuilderWriter();        
+        final StringBuilderWriter writer = new StringBuilderWriter();
         try {
             toSerializable(event, writer);
             return writer.toString();
@@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
         }
     }
 
+    private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
+        // TODO Jackson-based layouts have certain filters set up for Log4jLogEvent.
+        // TODO Need to set up the same filters for MutableLogEvent but don't know how...
+        // This is a workaround.
+        return event instanceof MutableLogEvent
+                ? Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation()))
+                : event;
+    }
+
     public void toSerializable(final LogEvent event, final Writer writer)
             throws JsonGenerationException, JsonMappingException, IOException {
-        objectWriter.writeValue(writer, event);
+        objectWriter.writeValue(writer, convertMutableToLog4jEvent(event));
         writer.write(eol);
         markEvent();
     }


[34/50] logging-log4j2 git commit: Use Java 7 diamonds.

Posted by mi...@apache.org.
Use Java 7 diamonds.

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

Branch: refs/heads/LOG4J2-1365
Commit: a6c32c5166db9bf7efc56ff34005511360715c7b
Parents: f275612
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:39:39 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:39:39 2016 -0700

----------------------------------------------------------------------
 .../log4j/perf/jmh/LoggerConfigBenchmark.java   |   2 +-
 ...ThreadLocalVsConcurrentHashMapBenchmark.java | 186 +++++++++----------
 2 files changed, 94 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a6c32c51/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/LoggerConfigBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/LoggerConfigBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/LoggerConfigBenchmark.java
index 161d4d1..0321b04 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/LoggerConfigBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/LoggerConfigBenchmark.java
@@ -51,7 +51,7 @@ import org.openjdk.jmh.infra.Blackhole;
 @State(Scope.Benchmark)
 public class LoggerConfigBenchmark {
 
-    private final CopyOnWriteArraySet<AppenderControl> appenderSet = new CopyOnWriteArraySet<AppenderControl>();
+    private final CopyOnWriteArraySet<AppenderControl> appenderSet = new CopyOnWriteArraySet<>();
     private volatile Filter filter = null;
     private final boolean additive = true;
     private final boolean includeLocation = true;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a6c32c51/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadLocalVsConcurrentHashMapBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadLocalVsConcurrentHashMapBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadLocalVsConcurrentHashMapBenchmark.java
index 7ba0ca4..7d1ccc9 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadLocalVsConcurrentHashMapBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadLocalVsConcurrentHashMapBenchmark.java
@@ -1,94 +1,94 @@
-/*
- * 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.perf.jmh;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.State;
-
-/**
- * Compares performance of ThreadLocal, vs ConcurrentHashMap&lt;Thread, Object&gt;.
- */
-// ============================== HOW TO RUN THIS TEST: ====================================
-// (Quick build: mvn -DskipTests=true clean package -pl log4j-perf -am )
-//
-// single thread:
-// java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsConcurrentHashMap.*" -f 1 -wi 10 -i 20 -tu ns -bm sample
-//
-// four threads:
-// java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsConcurrentHashMap.*" -f 1 -wi 10 -i 20 -tu ns -bm sample
-// -t 4
-//
-// Usage help:
-// java -jar log4j-perf/target/benchmarks.jar -help
-//
-@State(Scope.Benchmark)
-public class ThreadLocalVsConcurrentHashMapBenchmark {
-
-    private static final String VALUE = "value";
-    private static ConcurrentHashMap<Thread, StringBuilder> map = new ConcurrentHashMap<Thread, StringBuilder>();
-    private static ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
-
-    @Benchmark
-    public String newInstance() {
-        StringBuilder sb = getNew();
-        sb.append(VALUE);
-        return sb.toString();
-    }
-
-    @Benchmark
-    public String threadLocal() {
-        StringBuilder sb = getThreadLocal();
-        sb.append(VALUE);
-        return sb.toString();
-    }
-
-    @Benchmark
-    public String concurrentHashMap() {
-        StringBuilder sb = getConcurrentMap();
-        sb.append(VALUE);
-        return sb.toString();
-    }
-
-    private StringBuilder getNew() {
-        final StringBuilder buf = new StringBuilder();
-        return buf;
-    }
-
-    private StringBuilder getThreadLocal() {
-        StringBuilder buf = threadLocal.get();
-        if (buf == null) {
-            buf = new StringBuilder();
-            threadLocal.set(buf);
-        }
-        buf.setLength(0);
-        return buf;
-    }
-
-    private StringBuilder getConcurrentMap() {
-        StringBuilder buf = map.get(Thread.currentThread());
-        if (buf == null) {
-            buf = new StringBuilder();
-            map.put(Thread.currentThread(), buf);
-        }
-        buf.setLength(0);
-        return buf;
-    }
+/*
+ * 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.perf.jmh;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+
+/**
+ * Compares performance of ThreadLocal, vs ConcurrentHashMap&lt;Thread, Object&gt;.
+ */
+// ============================== HOW TO RUN THIS TEST: ====================================
+// (Quick build: mvn -DskipTests=true clean package -pl log4j-perf -am )
+//
+// single thread:
+// java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsConcurrentHashMap.*" -f 1 -wi 10 -i 20 -tu ns -bm sample
+//
+// four threads:
+// java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsConcurrentHashMap.*" -f 1 -wi 10 -i 20 -tu ns -bm sample
+// -t 4
+//
+// Usage help:
+// java -jar log4j-perf/target/benchmarks.jar -help
+//
+@State(Scope.Benchmark)
+public class ThreadLocalVsConcurrentHashMapBenchmark {
+
+    private static final String VALUE = "value";
+    private static ConcurrentHashMap<Thread, StringBuilder> map = new ConcurrentHashMap<>();
+    private static ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
+
+    @Benchmark
+    public String newInstance() {
+        StringBuilder sb = getNew();
+        sb.append(VALUE);
+        return sb.toString();
+    }
+
+    @Benchmark
+    public String threadLocal() {
+        StringBuilder sb = getThreadLocal();
+        sb.append(VALUE);
+        return sb.toString();
+    }
+
+    @Benchmark
+    public String concurrentHashMap() {
+        StringBuilder sb = getConcurrentMap();
+        sb.append(VALUE);
+        return sb.toString();
+    }
+
+    private StringBuilder getNew() {
+        final StringBuilder buf = new StringBuilder();
+        return buf;
+    }
+
+    private StringBuilder getThreadLocal() {
+        StringBuilder buf = threadLocal.get();
+        if (buf == null) {
+            buf = new StringBuilder();
+            threadLocal.set(buf);
+        }
+        buf.setLength(0);
+        return buf;
+    }
+
+    private StringBuilder getConcurrentMap() {
+        StringBuilder buf = map.get(Thread.currentThread());
+        if (buf == null) {
+            buf = new StringBuilder();
+            map.put(Thread.currentThread(), buf);
+        }
+        buf.setLength(0);
+        return buf;
+    }
 }
\ No newline at end of file


[32/50] logging-log4j2 git commit: Add final modifier to private fields.

Posted by mi...@apache.org.
Add final modifier to private 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/661e1179
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/661e1179
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/661e1179

Branch: refs/heads/LOG4J2-1365
Commit: 661e11790dd6e9663d9a3696cf8cb26afd47e4d8
Parents: fe80be3
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:32:48 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:32:48 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/661e1179/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java
index 888035d..7fd83fd 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TextEncoderHelperBenchmark.java
@@ -117,7 +117,7 @@ public class TextEncoderHelperBenchmark {
     }
 
     //private static final ThreadLocal<StringBuilderEncoder> textEncoderHelper = new ThreadLocal<>();
-    private StringBuilderEncoder textEncoderHelper = new StringBuilderEncoder(CHARSET_DEFAULT);
+    private final StringBuilderEncoder textEncoderHelper = new StringBuilderEncoder(CHARSET_DEFAULT);
     private StringBuilderEncoder getEncoder() {
         StringBuilderEncoder result = textEncoderHelper;
         return result;


[31/50] logging-log4j2 git commit: Remove unused imports.

Posted by mi...@apache.org.
Remove unused imports.

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

Branch: refs/heads/LOG4J2-1365
Commit: fe80be342e27f17e52640eea2190a94fd34545e8
Parents: 4a2ad0c
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:32:29 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:32:29 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/message/ParameterFormatterBenchmark.java  | 2 --
 .../main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java   | 1 -
 2 files changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fe80be34/log4j-perf/src/main/java/org/apache/logging/log4j/message/ParameterFormatterBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/message/ParameterFormatterBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/message/ParameterFormatterBenchmark.java
index d7dbf5d..49bc9ea 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/message/ParameterFormatterBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/message/ParameterFormatterBenchmark.java
@@ -19,8 +19,6 @@ package org.apache.logging.log4j.message;
 
 import java.util.concurrent.TimeUnit;
 
-import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.perf.jmh.ParameterizedMessageBenchmark;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
 import org.openjdk.jmh.annotations.Mode;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fe80be34/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
index 4b1a4ad..5f84975 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
@@ -21,7 +21,6 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.layout.Encoder;
 import org.apache.logging.log4j.core.layout.StringBuilderEncoder;
-import org.apache.logging.log4j.core.layout.TextEncoderHelper;
 import org.apache.logging.log4j.core.pattern.FormattingInfo;
 import org.apache.logging.log4j.core.pattern.PatternFormatter;
 


[11/50] logging-log4j2 git commit: LOG4J2-1334 ExtendedThrowablePatternProxy bugfix: a long time ago the method getThrownProxy() was added to the LogEvent interface, but ExtendedThrowablePatternProxy still required Log4jLogEvent

Posted by mi...@apache.org.
LOG4J2-1334 ExtendedThrowablePatternProxy bugfix: a long time ago the method getThrownProxy() was added to the LogEvent interface, but ExtendedThrowablePatternProxy still required Log4jLogEvent


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

Branch: refs/heads/LOG4J2-1365
Commit: b264c2188000debfb7e669c5dd5fac4e41ee4cc3
Parents: e323868
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 22:36:34 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 22:36:34 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/pattern/ExtendedThrowablePatternConverter.java   | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b264c218/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
index 6ed8c22..84d4e65 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ExtendedThrowablePatternConverter.java
@@ -59,10 +59,7 @@ public final class ExtendedThrowablePatternConverter extends ThrowablePatternCon
      */
     @Override
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
-        ThrowableProxy proxy = null;
-        if (event instanceof Log4jLogEvent) {
-            proxy = event.getThrownProxy();
-        }
+        ThrowableProxy proxy = event.getThrownProxy();
         final Throwable throwable = event.getThrown();
         if ((throwable != null || proxy != null) && options.anyLines()) {
             if (proxy == null) {


[37/50] logging-log4j2 git commit: Statement unnecessarily nested.

Posted by mi...@apache.org.
Statement unnecessarily nested.


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

Branch: refs/heads/LOG4J2-1365
Commit: b119e19d0713c7a2cc7fd4c85b94e2164b57872d
Parents: 8f1e0b2
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:47:35 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:47:35 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/lookup/CustomLookup.java     | 3 +--
 .../java/org/apache/logging/log4j/lookup/MapMessageLookup.java | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b119e19d/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/CustomLookup.java
----------------------------------------------------------------------
diff --git a/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/CustomLookup.java b/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/CustomLookup.java
index 471d2ba..fcd2c5c 100644
--- a/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/CustomLookup.java
+++ b/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/CustomLookup.java
@@ -67,9 +67,8 @@ public class CustomLookup extends AbstractLookup {
                 }
                 sb.append("}");
                 return sb.toString();
-            } else {
-                return properties.get(key);
             }
+            return properties.get(key);
         } catch (final Exception ex) {
             LOGGER.warn(LOOKUP, "Error while getting property [{}].", key, ex);
             return null;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b119e19d/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java
----------------------------------------------------------------------
diff --git a/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java b/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java
index 1ed1868..7a1faaa 100644
--- a/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java
+++ b/log4j-samples/loggerProperties/src/main/java/org/apache/logging/log4j/lookup/MapMessageLookup.java
@@ -70,16 +70,14 @@ public class MapMessageLookup extends AbstractLookup {
                     }
                     sb.append("}");
                     return sb.toString();
-                } else {
-                    return properties.get(key);
                 }
+                return properties.get(key);
             } catch (final Exception ex) {
                 LOGGER.warn(LOOKUP, "Error while getting property [{}].", key, ex);
                 return null;
             }
-        } else {
-            return null;
         }
+        return null;
     }
 
     public static void setLoggerProperties(String loggerName, Map<String, String> properties) {


[38/50] logging-log4j2 git commit: Replace depreacted test code with EasyMock.newCapture().

Posted by mi...@apache.org.
Replace depreacted test code with EasyMock.newCapture().

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

Branch: refs/heads/LOG4J2-1365
Commit: f30bd69f8b20e8aa23b77d96c7bad76d3fe4f55f
Parents: b119e19
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:50:19 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:50:19 2016 -0700

----------------------------------------------------------------------
 .../appender/NoSqlDatabaseManagerTest.java      | 26 ++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f30bd69f/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
index 7809451..c3c11d1 100644
--- a/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
+++ b/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
@@ -16,6 +16,21 @@
  */
 package org.apache.logging.log4j.nosql.appender;
 
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Date;
@@ -30,15 +45,12 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.message.Message;
 import org.easymock.Capture;
+import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.easymock.EasyMock.*;
-
-import static org.junit.Assert.*;
-
 public class NoSqlDatabaseManagerTest {
     private NoSqlConnection<Map<String, Object>, DefaultNoSqlObject> connection;
     private NoSqlProvider<NoSqlConnection<Map<String, Object>, DefaultNoSqlObject>> provider;
@@ -167,7 +179,7 @@ public class NoSqlDatabaseManagerTest {
             verify(this.provider, this.connection);
             reset(this.provider, this.connection);
 
-            final Capture<NoSqlObject<Map<String, Object>>> capture = new Capture<>();
+            final Capture<NoSqlObject<Map<String, Object>>> capture = EasyMock.newCapture();
 
             final LogEvent event = createStrictMock(LogEvent.class);
             final Message message = createStrictMock(Message.class);
@@ -256,7 +268,7 @@ public class NoSqlDatabaseManagerTest {
             verify(this.provider, this.connection);
             reset(this.provider, this.connection);
 
-            final Capture<NoSqlObject<Map<String, Object>>> capture = new Capture<>();
+            final Capture<NoSqlObject<Map<String, Object>>> capture = EasyMock.newCapture();
 
             final RuntimeException exception = new RuntimeException("This is something cool!");
             final Map<String, String> context = new HashMap<>();
@@ -393,7 +405,7 @@ public class NoSqlDatabaseManagerTest {
             verify(this.provider, this.connection);
             reset(this.provider, this.connection);
 
-            final Capture<NoSqlObject<Map<String, Object>>> capture = new Capture<>();
+            final Capture<NoSqlObject<Map<String, Object>>> capture = EasyMock.newCapture();
 
             final IOException exception1 = new IOException("This is the cause.");
             final SQLException exception2 = new SQLException("This is the result.", exception1);


[44/50] logging-log4j2 git commit: Fix per Matt's comments on the ML.

Posted by mi...@apache.org.
Fix per Matt's comments on the ML.

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

Branch: refs/heads/LOG4J2-1365
Commit: a990c75251bdc28123b48ceb67e54f7face71af7
Parents: 7380b27
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:03:45 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:03:45 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/net/server/TcpSocketServer.java   | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a990c752/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
index 9103a01..f32fbe8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.util.Log4jThread;
+import org.apache.logging.log4j.message.EntryMessage;
 
 /**
  * Listens for events over a socket connection.
@@ -56,7 +57,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
 
         @Override
         public void run() {
-            logger.traceEntry();
+            final EntryMessage entry = logger.traceEntry();
             boolean closed = false;
             try {
                 try {
@@ -80,7 +81,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
             } finally {
                 handlers.remove(Long.valueOf(getId()));
             }
-            logger.traceExit();
+            logger.traceExit(entry);
         }
 
         public void shutdown() {
@@ -218,7 +219,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
      */
     @Override
     public void run() {
-        logger.traceEntry();
+        final EntryMessage entry = logger.traceEntry();
         while (isActive()) {
             if (serverSocket.isClosed()) {
                 return;
@@ -240,14 +241,14 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
             } catch (final IOException e) {
                 if (serverSocket.isClosed()) {
                     // OK we're done.
-                    logger.traceExit();
+                    logger.traceExit(entry);
                     return;
                 }
                 logger.error("Exception encountered on accept. Ignoring. Stack Trace :", e);
             }
         }
-        for (final Map.Entry<Long, SocketHandler> entry : handlers.entrySet()) {
-            final SocketHandler handler = entry.getValue();
+        for (final Map.Entry<Long, SocketHandler> handlerEntry : handlers.entrySet()) {
+            final SocketHandler handler = handlerEntry.getValue();
             handler.shutdown();
             try {
                 handler.join();
@@ -255,7 +256,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
                 // Ignore the exception
             }
         }
-        logger.traceExit();
+        logger.traceExit(entry);
     }
 
     /**
@@ -264,10 +265,10 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
      * @throws IOException if the server socket could not be closed
      */
     public void shutdown() throws IOException {
-        logger.traceEntry();
+        final EntryMessage entry = logger.traceEntry();
         setActive(false);
         Thread.currentThread().interrupt();
         serverSocket.close();
-        logger.traceExit();
+        logger.traceExit(entry);
     }
 }


[15/50] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent and ReusableLogEventFactory improvements

Posted by mi...@apache.org.
LOG4J2-1334 MutableLogEvent and ReusableLogEventFactory improvements

- better comments
- use size constants defined in Constants
- trim message size back to max in clear()
- implement ThreadNameCachingStrategy


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

Branch: refs/heads/LOG4J2-1365
Commit: a743e8ee5705ed4188ef2f8dcc7052c1ff3378c4
Parents: 7cbc43f
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 14:34:21 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 14:34:21 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/MutableLogEvent.java        | 33 ++++++++++++--------
 .../core/impl/ReusableLogEventFactory.java      | 23 ++++++++------
 2 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a743e8ee/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 3dce409..e86c553 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -1,5 +1,9 @@
 package org.apache.logging.log4j.core.impl;
 
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.util.Map;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.ThreadContext;
@@ -8,20 +12,13 @@ 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 java.io.InvalidObjectException;
-import java.io.ObjectInputStream;
-import java.util.Map;
-
 /**
  * Mutable implementation of the {@code LogEvent} interface.
  * @since 2.6
  */
 public class MutableLogEvent implements LogEvent, ReusableMessage {
-    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 final Object[] PARAMS = new Object[0];
     private static final Message EMPTY = new SimpleMessage(Strings.EMPTY);
 
@@ -44,10 +41,6 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
     private long nanoTime;
     private StringBuilder messageText;
 
-    private static int size(final String property, final int defaultValue) {
-        return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
-    }
-
     /**
      * Initialize the fields of this {@code MutableLogEvent} from another event.
      * Similar in purpose and usage as {@link org.apache.logging.log4j.core.impl.Log4jLogEvent.LogEventProxy},
@@ -88,7 +81,13 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         source = null;
         contextMap = null;
         contextStack = null;
-        // threadName = null; // THreadName should not be cleared
+
+        // ThreadName should not be cleared: this field is set in the ReusableLogEventFactory
+        // where this instance is kept in a ThreadLocal, so it usually does not change.
+        // threadName = null; // no need to clear threadName
+
+        trimMessageText();
+
         // primitive fields that cannot be cleared:
         //timeMillis;
         //threadId;
@@ -98,6 +97,14 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         //nanoTime;
     }
 
+    // ensure that excessively long char[] arrays are not kept in memory forever
+    private void trimMessageText() {
+        if (messageText != null && messageText.length() > Constants.MAX_REUSABLE_MESSAGE_SIZE) {
+            messageText.setLength(Constants.MAX_REUSABLE_MESSAGE_SIZE);
+            messageText.trimToSize();
+        }
+    }
+
     @Override
     public String getLoggerFqcn() {
         return loggerFqcn;
@@ -158,7 +165,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         if (messageText == null) {
             // Should never happen:
             // only happens if user logs a custom reused message when Constants.ENABLE_THREADLOCALS is false
-            messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
+            messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
         }
         messageText.setLength(0);
         return messageText;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a743e8ee/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
index 2912d91..f396a4c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
@@ -16,26 +16,28 @@
  */
 package org.apache.logging.log4j.core.impl;
 
+import java.util.List;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy;
 import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.TimestampMessage;
 
-import java.util.List;
-
 /**
  * Garbage-free LogEventFactory that reuses a single mutable log event.
  * @since 2.6
  */
 public class ReusableLogEventFactory implements LogEventFactory {
+    private static final ThreadNameCachingStrategy THREAD_NAME_CACHING_STRATEGY = ThreadNameCachingStrategy.create();
+    private static final Clock CLOCK = ClockFactory.getClock();
 
     private static ThreadLocal<MutableLogEvent> mutableLogEventThreadLocal = new ThreadLocal<>();
-    private static final Clock CLOCK = ClockFactory.getClock();
     /**
      * Creates a log event.
      *
@@ -55,12 +57,14 @@ public class ReusableLogEventFactory implements LogEventFactory {
         MutableLogEvent result = mutableLogEventThreadLocal.get();
         if (result == null) {
             result = new MutableLogEvent();
+
+            // usually no need to re-initialize thread-specific fields since the event is stored in a ThreadLocal
             result.setThreadId(Thread.currentThread().getId());
-            result.setThreadName(Thread.currentThread().getName());
+            result.setThreadName(Thread.currentThread().getName()); // Thread.getName() allocates Objects on each call
             result.setThreadPriority(Thread.currentThread().getPriority());
             mutableLogEventThreadLocal.set(result);
         }
-        result.clear();
+        result.clear(); // ensure any previously cached values (thrownProxy, source, etc.) are cleared
 
         result.setLoggerName(loggerName);
         result.setMarker(marker);
@@ -75,11 +79,10 @@ public class ReusableLogEventFactory implements LogEventFactory {
                 : CLOCK.currentTimeMillis());
         result.setNanoTime(Log4jLogEvent.getNanoClock().nanoTime());
 
-        // TODO
-//        result.setEndOfBatch();
-//        result.setIncludeLocation();
-//        result.setSource();
-        //return new Log4jLogEvent(loggerName, marker, fqcn, level, data, properties, t);
+        if (THREAD_NAME_CACHING_STRATEGY == ThreadNameCachingStrategy.UNCACHED) {
+            result.setThreadName(Thread.currentThread().getName()); // Thread.getName() allocates Objects on each call
+            result.setThreadPriority(Thread.currentThread().getPriority());
+        }
         return result;
     }
 }


[14/50] logging-log4j2 git commit: LOG4J2-1334 moved two constants from RingBufferLogEvent to Constants so they can be used in MutableLogEvent

Posted by mi...@apache.org.
LOG4J2-1334 moved two constants from RingBufferLogEvent to Constants so they can be used in MutableLogEvent


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

Branch: refs/heads/LOG4J2-1365
Commit: 7cbc43fedda1bd69101282c87ba167aecf2a99f5
Parents: 2468c8c
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 14:32:01 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 14:32:01 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/async/RingBufferLogEvent.java        | 15 ++++-----------
 .../apache/logging/log4j/core/util/Constants.java   | 16 +++++++++++++++-
 2 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7cbc43fe/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 f3ad22f..6929596 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
@@ -33,7 +33,6 @@ 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.message.TimestampMessage;
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.Strings;
 
 import com.lmax.disruptor.EventFactory;
@@ -48,15 +47,9 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
     public static final Factory FACTORY = new Factory();
 
     private static final long serialVersionUID = 8462119088943934758L;
-    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 final Object[] PARAMS = new Object[0];
     private static final Message EMPTY = new SimpleMessage(Strings.EMPTY);
 
-    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.
      */
@@ -66,7 +59,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
         public RingBufferLogEvent newInstance() {
             RingBufferLogEvent result = new RingBufferLogEvent();
             if (Constants.ENABLE_THREADLOCALS) {
-                result.messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
+                result.messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
             }
             return result;
         }
@@ -130,7 +123,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
         if (messageText == null) {
             // Should never happen:
             // only happens if user logs a custom reused message when Constants.ENABLE_THREADLOCALS is false
-            messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
+            messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
         }
         messageText.setLength(0);
         return messageText;
@@ -356,8 +349,8 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
 
     // ensure that excessively long char[] arrays are not kept in memory forever
     private void trimMessageText() {
-        if (messageText != null && messageText.length() > MAX_REUSABLE_MESSAGE_SIZE) {
-            messageText.setLength(MAX_REUSABLE_MESSAGE_SIZE);
+        if (messageText != null && messageText.length() > Constants.MAX_REUSABLE_MESSAGE_SIZE) {
+            messageText.setLength(Constants.MAX_REUSABLE_MESSAGE_SIZE);
             messageText.trimToSize();
         }
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7cbc43fe/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index 54e0a86..95bd03e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -19,7 +19,6 @@ package org.apache.logging.log4j.core.util;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -108,6 +107,21 @@ public final class Constants {
             //AsyncLoggerContextSelector.class.getName().equals(PropertiesUtil.getProperties().getStringProperty(LOG4J_CONTEXT_SELECTOR)));
 
     /**
+     * Initial StringBuilder size used in RingBuffer LogEvents to store the contents of reusable Messages.
+     */
+    public static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
+
+    /**
+     * Maximum size of the StringBuilders used in RingBuffer LogEvents to store the contents of reusable Messages.
+     * After a large message has been delivered to the appenders, the StringBuilder is trimmed to this size.
+     */
+    public 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);
+    }
+
+    /**
      * Prevent class instantiation.
      */
     private Constants() {


[39/50] logging-log4j2 git commit: Do not use our own deprecated code.

Posted by mi...@apache.org.
Do not use our own deprecated code.

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

Branch: refs/heads/LOG4J2-1365
Commit: 5f692411a4568946ae4dfe053c9de19635dde18e
Parents: f30bd69
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:52:55 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:52:55 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/net/server/TcpSocketServer.java        | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5f692411/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
index db5917c..9103a01 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
@@ -56,7 +56,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
 
         @Override
         public void run() {
-            logger.entry();
+            logger.traceEntry();
             boolean closed = false;
             try {
                 try {
@@ -80,7 +80,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
             } finally {
                 handlers.remove(Long.valueOf(getId()));
             }
-            logger.exit();
+            logger.traceExit();
         }
 
         public void shutdown() {
@@ -218,7 +218,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
      */
     @Override
     public void run() {
-        logger.entry();
+        logger.traceEntry();
         while (isActive()) {
             if (serverSocket.isClosed()) {
                 return;
@@ -240,7 +240,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
             } catch (final IOException e) {
                 if (serverSocket.isClosed()) {
                     // OK we're done.
-                    logger.exit();
+                    logger.traceExit();
                     return;
                 }
                 logger.error("Exception encountered on accept. Ignoring. Stack Trace :", e);
@@ -255,7 +255,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
                 // Ignore the exception
             }
         }
-        logger.exit();
+        logger.traceExit();
     }
 
     /**
@@ -264,10 +264,10 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
      * @throws IOException if the server socket could not be closed
      */
     public void shutdown() throws IOException {
-        logger.entry();
+        logger.traceEntry();
         setActive(false);
         Thread.currentThread().interrupt();
         serverSocket.close();
-        logger.exit();
+        logger.traceExit();
     }
 }


[17/50] logging-log4j2 git commit: LOG4J2-1274 moved ByteBuffer size from OutputStreamManager to Constants, improved Constants docs

Posted by mi...@apache.org.
LOG4J2-1274	moved ByteBuffer size from OutputStreamManager to Constants, improved Constants docs


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

Branch: refs/heads/LOG4J2-1365
Commit: 554086869fe0a49fb1edd9dae4f257c393baab9a
Parents: 7a9d18c
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 15:27:10 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 15:27:10 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/appender/FileManager.java  |  3 ++-
 .../logging/log4j/core/appender/OutputStreamManager.java |  7 +++----
 .../log4j/core/appender/rolling/RollingFileManager.java  |  4 ++--
 .../logging/log4j/core/layout/ByteBufferDestination.java |  8 +++++---
 .../org/apache/logging/log4j/core/util/Constants.java    | 11 +++++++++++
 5 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55408686/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index 43372b6..060f2db 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.util.Constants;
 
 
 /**
@@ -213,7 +214,7 @@ public class FileManager extends OutputStreamManager {
             OutputStream os;
             try {
                 os = new FileOutputStream(name, data.append);
-                final int actualSize = data.bufferedIO ? data.bufferSize : DEFAULT_BUFFER_SIZE;
+                final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
                 return new FileManager(name, os, data.append, data.locking, data.advertiseURI, data.layout,
                         writeHeader, buffer);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55408686/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
index b22f083..20ef401 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
@@ -23,21 +23,20 @@ import java.util.Objects;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Constants;
 
 /**
  * Manages an OutputStream so that it can be shared by multiple Appenders and will
  * allow appenders to reconfigure without requiring a new stream.
  */
 public class OutputStreamManager extends AbstractManager implements ByteBufferDestination {
-    protected static final int DEFAULT_BUFFER_SIZE = 8 * 1024;
-
-    private volatile OutputStream os;
     protected final Layout<?> layout;
     protected ByteBuffer byteBuffer;
+    private volatile OutputStream os;
 
     protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout,
             final boolean writeHeader) {
-        this(os, streamName, layout, writeHeader, ByteBuffer.wrap(new byte[DEFAULT_BUFFER_SIZE]));
+        this(os, streamName, layout, writeHeader, ByteBuffer.wrap(new byte[Constants.ENCODER_BYTE_BUFFER_SIZE]));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55408686/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index d0b0735..9c573eb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -61,7 +61,7 @@ public class RollingFileManager extends FileManager {
             final RolloverStrategy rolloverStrategy, final String advertiseURI,
             final Layout<? extends Serializable> layout, final int bufferSize, final boolean writeHeader) {
         this(fileName, pattern, os, append, size, time, triggeringPolicy, rolloverStrategy, advertiseURI, layout,
-                writeHeader, ByteBuffer.wrap(new byte[DEFAULT_BUFFER_SIZE]));
+                writeHeader, ByteBuffer.wrap(new byte[Constants.ENCODER_BYTE_BUFFER_SIZE]));
     }
 
     protected RollingFileManager(final String fileName, final String pattern, final OutputStream os,
@@ -416,7 +416,7 @@ public class RollingFileManager extends FileManager {
             OutputStream os;
             try {
                 os = new FileOutputStream(name, data.append);
-                final int actualSize = data.bufferedIO ? data.bufferSize : DEFAULT_BUFFER_SIZE;
+                final int actualSize = data.bufferedIO ? data.bufferSize : Constants.ENCODER_BYTE_BUFFER_SIZE;
                 final ByteBuffer buffer = ByteBuffer.wrap(new byte[actualSize]);
 
                 final long time = file.lastModified(); // LOG4J2-531 create file first so time has valid value

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55408686/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ByteBufferDestination.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ByteBufferDestination.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ByteBufferDestination.java
index 61ce3ba..88b8464 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ByteBufferDestination.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ByteBufferDestination.java
@@ -19,9 +19,11 @@ package org.apache.logging.log4j.core.layout;
 import java.nio.ByteBuffer;
 
 /**
- * ByteBufferDestination addresses the problem a producer has when the destination ByteBuffer is not large enough to
- * fit all the data. This interface allows a producer to write arbitrary amounts of data to a destination.
- *
+ * ByteBufferDestination is the destination that {@link Encoder}s write binary data to. It encapsulates a
+ * {@code ByteBuffer} and a {@code drain()} method the producer can call when the {@code ByteBuffer} is full.
+ * <p>
+ * This interface allows a producer to write arbitrary amounts of data to a destination.
+ * </p>
  * @since 2.6
  */
 public interface ByteBufferDestination {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/55408686/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index e1f175b..ef9764a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -135,6 +135,17 @@ public final class Constants {
      */
     public static final int ENCODER_CHAR_BUFFER_SIZE = size("log4j.encoder.charBufferSize", 2048);
 
+    /**
+     * Default size of ByteBuffers used to encode LogEvents without allocating temporary objects.
+     * <p>
+     * The default value is {@value}, users can override with system property "log4j.encoder.byteBufferSize".
+     * </p>
+     * @see org.apache.logging.log4j.core.layout.ByteBufferDestination
+     * @since 2.6
+     */
+    public static final int ENCODER_BYTE_BUFFER_SIZE = size("log4j.encoder.byteBufferSize", 8 * 1024);
+
+
     private static int size(final String property, final int defaultValue) {
         return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
     }


[05/50] logging-log4j2 git commit: LOG4J2-1334 ReusableLogEventFactory various fixes

Posted by mi...@apache.org.
LOG4J2-1334 ReusableLogEventFactory various fixes


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

Branch: refs/heads/LOG4J2-1365
Commit: dc9b6afe0c3b46d57f88671802134574d6b530fa
Parents: adcdfc0
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:39:22 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:39:22 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/ReusableLogEventFactory.java       | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc9b6afe/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
index 190b27a..2912d91 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
@@ -24,11 +24,13 @@ import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.TimestampMessage;
 
 import java.util.List;
 
 /**
  * Garbage-free LogEventFactory that reuses a single mutable log event.
+ * @since 2.6
  */
 public class ReusableLogEventFactory implements LogEventFactory {
 
@@ -41,14 +43,14 @@ public class ReusableLogEventFactory implements LogEventFactory {
      * @param marker An optional Marker.
      * @param fqcn The fully qualified class name of the caller.
      * @param level The event Level.
-     * @param data The Message.
+     * @param message The Message.
      * @param properties Properties to be added to the log event.
      * @param t An optional Throwable.
      * @return The LogEvent.
      */
     @Override
     public LogEvent createEvent(final String loggerName, final Marker marker,
-                                final String fqcn, final Level level, final Message data,
+                                final String fqcn, final Level level, final Message message,
                                 final List<Property> properties, final Throwable t) {
         MutableLogEvent result = mutableLogEventThreadLocal.get();
         if (result == null) {
@@ -58,16 +60,19 @@ public class ReusableLogEventFactory implements LogEventFactory {
             result.setThreadPriority(Thread.currentThread().getPriority());
             mutableLogEventThreadLocal.set(result);
         }
+        result.clear();
 
         result.setLoggerName(loggerName);
         result.setMarker(marker);
         result.setLoggerFqcn(fqcn);
         result.setLevel(level == null ? Level.OFF : level);
-        result.setMessage(data);
+        result.setMessage(message);
         result.setThrown(t);
         result.setContextMap(Log4jLogEvent.createMap(properties));
         result.setContextStack(ThreadContext.getDepth() == 0 ? null : ThreadContext.cloneStack());// mutable copy
-        result.setTimeMillis(CLOCK.currentTimeMillis());
+        result.setTimeMillis(message instanceof TimestampMessage
+                ? ((TimestampMessage) message).getTimestamp()
+                : CLOCK.currentTimeMillis());
         result.setNanoTime(Log4jLogEvent.getNanoClock().nanoTime());
 
         // TODO


[23/50] logging-log4j2 git commit: [LOG4J2-1362] Create a YAML layout.

Posted by mi...@apache.org.
[LOG4J2-1362] Create a YAML 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/80a43988
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/80a43988
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/80a43988

Branch: refs/heads/LOG4J2-1365
Commit: 80a43988a017a8e95f6188386cd5fe7ddf3945bd
Parents: 71fbda8
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 15:27:19 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 15:27:19 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/log4j/util/Strings.java  |  12 +
 .../log4j/core/jackson/Log4jYamlModule.java     |  48 ++++
 .../core/jackson/Log4jYamlObjectMapper.java     |  41 +++
 .../log4j/core/layout/JacksonFactory.java       |  34 +++
 .../logging/log4j/core/layout/YamlLayout.java   | 193 +++++++++++++
 .../logging/log4j/MarkerMixInYamlTest.java      |  31 ++
 .../log4j/core/jackson/LevelMixInYamlTest.java  |  29 ++
 .../jackson/StackTraceElementMixInTest.java     |   5 +
 .../log4j/core/layout/YamlLayoutTest.java       | 287 +++++++++++++++++++
 .../log4j/web/ServletRequestThreadContext.java  |  29 ++
 10 files changed, 709 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
index 6ee7dca..294b771 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.util;
 
+import java.util.Locale;
+
 /**
  * <em>Consider this class private.</em>
  * 
@@ -127,6 +129,16 @@ public final class Strings {
     }
 
     /**
+     * Shorthand for {@code str.toUpperCase(Locale.ROOT);}
+     * @param str The string to upper case.
+     * @return a new string
+     * @see String#toLowerCase(Locale)
+     */
+    public String toRootUpperCase(final String str) {
+        return str.toUpperCase(Locale.ROOT);
+    }
+    
+    /**
      * <p>
      * Removes control characters (char &lt;= 32) from both ends of this String returning {@code null} if the String is
      * empty ("") after the trim or if it is {@code null}.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java
new file mode 100644
index 0000000..4052320
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlModule.java
@@ -0,0 +1,48 @@
+/*
+ * 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.jackson;
+
+import org.apache.logging.log4j.core.jackson.Initializers.SetupContextInitializer;
+import org.apache.logging.log4j.core.jackson.Initializers.SimpleModuleInitializer;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+/**
+ * <p>
+ * <em>Consider this class private.</em>
+ * </p>
+ */
+final class Log4jYamlModule extends SimpleModule {
+
+    private static final long serialVersionUID = 1L;
+
+    Log4jYamlModule() {
+        super(Log4jYamlModule.class.getName(), new Version(2, 0, 0, null, null, null));
+        // MUST init here.
+        // Calling this from setupModule is too late!
+        //noinspection ThisEscapedInObjectConstruction
+        new SimpleModuleInitializer().initialize(this);
+    }
+
+    @Override
+    public void setupModule(final SetupContext context) {
+        // Calling super is a MUST!
+        super.setupModule(context);
+        new SetupContextInitializer().setupModule(context);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java
new file mode 100644
index 0000000..9ab787a
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Log4jYamlObjectMapper.java
@@ -0,0 +1,41 @@
+/*
+ * 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.jackson;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
+
+/**
+ * A Jackson {@link ObjectMapper} initialized for Log4j.
+ * <p>
+ * <em>Consider this class private.</em>
+ * </p>
+ */
+public class Log4jYamlObjectMapper extends YAMLMapper {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Create a new instance using the {@link Log4jYamlModule}.
+     */
+    public Log4jYamlObjectMapper() {
+        this.registerModule(new Log4jYamlModule());
+        this.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
index 537b634..44731f4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JacksonFactory.java
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.jackson.JsonConstants;
 import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
 import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
+import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
 import org.apache.logging.log4j.core.jackson.XmlConstants;
 
 import com.fasterxml.jackson.core.PrettyPrinter;
@@ -103,6 +104,39 @@ abstract class JacksonFactory {
         }
     }
 
+    static class YAML extends JacksonFactory {
+
+        @Override
+        protected String getPropertNameForContextMap() {
+            return JsonConstants.ELT_CONTEXT_MAP;
+        }
+
+        @Override
+        protected String getPropertNameForSource() {
+            return JsonConstants.ELT_SOURCE;
+        }
+
+        @Override
+        protected String getPropertNameForNanoTime() {
+            return JsonConstants.ELT_NANO_TIME;
+        }
+
+        @Override
+        protected PrettyPrinter newCompactPrinter() {
+            return new MinimalPrettyPrinter();
+        }
+
+        @Override
+        protected ObjectMapper newObjectMapper() {
+            return new Log4jYamlObjectMapper();
+        }
+
+        @Override
+        protected PrettyPrinter newPrettyPrinter() {
+            return new DefaultPrettyPrinter();
+        }
+    }
+
     abstract protected String getPropertNameForContextMap();
 
     abstract protected String getPropertNameForSource();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
new file mode 100644
index 0000000..0426fea
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/YamlLayout.java
@@ -0,0 +1,193 @@
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+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.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+
+/**
+ * Appends a series of YAML events as strings serialized as bytes.
+ *
+ * <h3>Complete well-formed YAML vs. fragment YAML</h3>
+ * <p>
+ * If you configure {@code complete="true"}, the appender outputs a well-formed YAML document. By default, with
+ * {@code complete="false"}, you should include the output as an <em>external file</em> in a separate file to form a
+ * well-formed YAML document.
+ * </p>
+ * <p>
+ * A well-formed YAML event follows this pattern:
+ * </p>
+ *
+ * <pre>
+ * 
+ * </pre>
+ * <p>
+ * If {@code complete="false"}, the appender does not write the YAML open array character "[" at the start of the
+ * document, "]" and the end, nor comma "," between records.
+ * </p>
+ * <p>
+ * This approach enforces the independence of the YamlLayout and the appender where you embed it.
+ * </p>
+ * <h3>Encoding</h3>
+ * <p>
+ * Appenders using this layout should have their {@code charset} set to {@code UTF-8} or {@code UTF-16}, otherwise
+ * events containing non ASCII characters could result in corrupted log files.
+ * </p>
+ * <h3>Pretty vs. compact YAML</h3>
+ * <p>
+ * By default, the YAML layout is not compact (a.k.a. "pretty") with {@code compact="false"}, which means the appender
+ * uses end-of-line characters and indents lines to format the text. If {@code compact="true"}, then no end-of-line or
+ * indentation is used. Message content may contain, of course, escaped end-of-lines.
+ * </p>
+ */
+@Plugin(name = "JsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public final class YamlLayout extends AbstractJacksonLayout {
+
+    private static final String DEFAULT_FOOTER = ""; // TODO maybe
+
+    private static final String DEFAULT_HEADER = ""; // TODO maybe
+
+    static final String CONTENT_TYPE = "application/yaml";
+
+    protected YamlLayout(final Configuration config, final boolean locationInfo, final boolean properties,
+            final boolean complete, final boolean compact, final boolean eventEol, final String headerPattern,
+            final String footerPattern, final Charset charset) {
+        super(config, new JacksonFactory.YAML().newWriter(locationInfo, properties, compact), charset, compact,
+                complete, eventEol,
+                PatternLayout.createSerializer(config, null, headerPattern, DEFAULT_HEADER, null, false, false),
+                PatternLayout.createSerializer(config, null, footerPattern, DEFAULT_FOOTER, null, false, false));
+    }
+
+    /**
+     * Returns appropriate YAML header.
+     *
+     * @return a byte array containing the header, opening the YAML array.
+     */
+    @Override
+    public byte[] getHeader() {
+        if (!this.complete) {
+            return null;
+        }
+        final StringBuilder buf = new StringBuilder();
+        final String str = serializeToString(getHeaderSerializer());
+        if (str != null) {
+            buf.append(str);
+        }
+        buf.append(this.eol);
+        return getBytes(buf.toString());
+    }
+
+    /**
+     * Returns appropriate YAML footer.
+     *
+     * @return a byte array containing the footer, closing the YAML array.
+     */
+    @Override
+    public byte[] getFooter() {
+        if (!this.complete) {
+            return null;
+        }
+        final StringBuilder buf = new StringBuilder();
+        buf.append(this.eol);
+        final String str = serializeToString(getFooterSerializer());
+        if (str != null) {
+            buf.append(str);
+        }
+        buf.append(this.eol);
+        return getBytes(buf.toString());
+    }
+
+    @Override
+    public Map<String, String> getContentFormat() {
+        final Map<String, String> result = new HashMap<>();
+        result.put("version", "2.0");
+        return result;
+    }
+
+    @Override
+    /**
+     * @return The content type.
+     */
+    public String getContentType() {
+        return CONTENT_TYPE + "; charset=" + this.getCharset();
+    }
+
+    /**
+     * Creates a YAML Layout.
+     * 
+     * @param config
+     *            The plugin configuration.
+     * @param locationInfo
+     *            If "true", includes the location information in the generated YAML.
+     * @param properties
+     *            If "true", includes the thread context in the generated YAML.
+     * @param headerPattern
+     *            The header pattern, defaults to {@code ""} if null.
+     * @param footerPattern
+     *            The header pattern, defaults to {@code ""} if null.
+     * @param footerPattern
+     * @param charset
+     *            The character set to use, if {@code null}, uses "UTF-8".
+     * @return A YAML Layout.
+     */
+    @PluginFactory
+    public static AbstractJacksonLayout createLayout(
+            // @formatter:off
+            @PluginConfiguration final Configuration config,
+            @PluginAttribute(value = "locationInfo", defaultBoolean = false) final boolean locationInfo,
+            @PluginAttribute(value = "properties", defaultBoolean = false) final boolean properties,
+            @PluginAttribute(value = "header", defaultString = DEFAULT_HEADER) final String headerPattern,
+            @PluginAttribute(value = "footer", defaultString = DEFAULT_FOOTER) final String footerPattern,
+            @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset
+            // @formatter:on
+    ) {
+        return new YamlLayout(config, locationInfo, properties, false, false, true, headerPattern, footerPattern,
+                charset);
+    }
+
+    /**
+     * Creates a YAML Layout using the default settings. Useful for testing.
+     *
+     * @return A YAML Layout.
+     */
+    public static AbstractJacksonLayout createDefaultLayout() {
+        return new YamlLayout(new DefaultConfiguration(), false, false, false, false, false, DEFAULT_HEADER,
+                DEFAULT_FOOTER, StandardCharsets.UTF_8);
+    }
+
+    @Override
+    public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
+        if (complete && eventCount > 0) {
+            writer.append(", ");
+        }
+        super.toSerializable(event, writer);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java
new file mode 100644
index 0000000..89f02a1
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java
@@ -0,0 +1,31 @@
+/*
+* 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;
+
+import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class MarkerMixInYamlTest extends MarkerMixInTest {
+
+    @Override
+    protected ObjectMapper newObjectMapper() {
+        return new Log4jYamlObjectMapper();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInYamlTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInYamlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInYamlTest.java
new file mode 100644
index 0000000..cff034e
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/LevelMixInYamlTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.jackson;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class LevelMixInYamlTest extends LevelMixInTest {
+
+    @Override
+    protected ObjectMapper newObjectMapper() {
+        return new Log4jYamlObjectMapper();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixInTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixInTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixInTest.java
index ed9b3da..5f3383b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixInTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/jackson/StackTraceElementMixInTest.java
@@ -34,6 +34,11 @@ public class StackTraceElementMixInTest {
         this.roundtrip(new Log4jJsonObjectMapper());
     }
 
+    @Test
+    public void testLog4jYamlObjectMapper() throws Exception {
+        this.roundtrip(new Log4jYamlObjectMapper());
+    }
+
     /**
      * @param mapper
      * @throws JsonProcessingException

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/YamlLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/YamlLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/YamlLayoutTest.java
new file mode 100644
index 0000000..fd30bbd
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/YamlLayoutTest.java
@@ -0,0 +1,287 @@
+/*
+ * 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.layout;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.BasicConfigurationFactory;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Tests the YamlLayout class.
+ */
+public class YamlLayoutTest {
+    static ConfigurationFactory cf = new BasicConfigurationFactory();
+
+    private static final String DQUOTE = "\"";
+
+    @AfterClass
+    public static void cleanupClass() {
+        ConfigurationFactory.removeConfigurationFactory(cf);
+        ThreadContext.clearAll();
+    }
+
+    @BeforeClass
+    public static void setupClass() {
+        ThreadContext.clearAll();
+        ConfigurationFactory.setConfigurationFactory(cf);
+        final LoggerContext ctx = LoggerContext.getContext();
+        ctx.reconfigure();
+    }
+
+    LoggerContext ctx = LoggerContext.getContext();
+
+    Logger rootLogger = this.ctx.getLogger("");
+
+    private void checkAt(final String expected, final int lineIndex, final List<String> list) {
+        final String trimedLine = list.get(lineIndex).trim();
+        assertTrue("Incorrect line index " + lineIndex + ": " + Strings.dquote(trimedLine),
+                trimedLine.equals(expected));
+    }
+
+    private void checkContains(final String expected, final List<String> list) {
+        for (final String string : list) {
+            final String trimedLine = string.trim();
+            if (trimedLine.equals(expected)) {
+                return;
+            }
+        }
+        Assert.fail("Cannot find " + expected + " in " + list);
+    }
+
+    private void checkMapEntry(final String key, final String value, final boolean compact, final String str) {
+        final String propSep = this.toPropertySeparator(compact, true);
+        // "name":"value"
+        final String expected = String.format("- key: \"%s\"\n  value: \"%s\"", key, value);
+        assertTrue("Cannot find " + expected + " in " + str, str.contains(expected));
+    }
+
+    private void checkProperty(final String key, final String value, final boolean compact, final String str,
+            final boolean isValue) {
+        final String propSep = this.toPropertySeparator(compact, isValue);
+        // {"key":"MDC.B","value":"B_Value"}
+        final String expected = String.format("%s%s\"%s\"", key, propSep, value);
+        assertTrue("Cannot find " + expected + " in " + str, str.contains(expected));
+    }
+
+    private void checkPropertyName(final String name, final boolean compact, final String str, final boolean isValue) {
+        final String propSep = this.toPropertySeparator(compact, isValue);
+        assertTrue(str, str.contains(name + propSep));
+    }
+
+    private void testAllFeatures(final boolean includeSource, final boolean compact, final boolean eventEol,
+            final boolean includeContext) throws Exception {
+        final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
+        final AbstractJacksonLayout layout = YamlLayout.createLayout(null, includeSource, includeContext, null, null,
+                StandardCharsets.UTF_8);
+        final String str = layout.toSerializable(expected);
+        // System.out.println(str);
+        final String propSep = this.toPropertySeparator(compact, true);
+        // Just check for \n since \r might or might not be there.
+        assertEquals(str, !compact || eventEol, str.contains("\n"));
+        assertEquals(str, includeSource, str.contains("source"));
+        assertEquals(str, includeContext, str.contains("contextMap"));
+        final Log4jLogEvent actual = new Log4jYamlObjectMapper().readValue(str, Log4jLogEvent.class);
+        LogEventFixtures.assertEqualLogEvents(expected, actual, includeSource, includeContext);
+        if (includeContext) {
+            this.checkMapEntry("MDC.A", "A_Value", compact, str);
+            this.checkMapEntry("MDC.B", "B_Value", compact, str);
+        }
+        //
+        assertNull(actual.getThrown());
+        // make sure the names we want are used
+        this.checkPropertyName("timeMillis", compact, str, true);
+        this.checkPropertyName("thread", compact, str, true); // and not threadName
+        this.checkPropertyName("level", compact, str, true);
+        this.checkPropertyName("loggerName", compact, str, true);
+        this.checkPropertyName("marker", compact, str, false);
+        this.checkPropertyName("name", compact, str, true);
+        this.checkPropertyName("parents", compact, str, false);
+        this.checkPropertyName("message", compact, str, true);
+        this.checkPropertyName("thrown", compact, str, false);
+        this.checkPropertyName("cause", compact, str, false);
+        this.checkPropertyName("class", compact, str, true);
+        this.checkPropertyName("method", compact, str, true);
+        this.checkPropertyName("file", compact, str, true);
+        this.checkPropertyName("line", compact, str, true);
+        this.checkPropertyName("exact", compact, str, true);
+        this.checkPropertyName("location", compact, str, true);
+        this.checkPropertyName("version", compact, str, true);
+        this.checkPropertyName("commonElementCount", compact, str, true);
+        this.checkPropertyName("localizedMessage", compact, str, true);
+        this.checkPropertyName("extendedStackTrace", compact, str, false);
+        this.checkPropertyName("suppressed", compact, str, false);
+        this.checkPropertyName("loggerFqcn", compact, str, true);
+        this.checkPropertyName("endOfBatch", compact, str, true);
+        if (includeContext) {
+            this.checkPropertyName("contextMap", compact, str, false);
+        }
+        this.checkPropertyName("contextStack", compact, str, false);
+        if (includeSource) {
+            this.checkPropertyName("source", compact, str, false);
+        }
+        // check some attrs
+        this.checkProperty("loggerFqcn", "f.q.c.n", compact, str, true);
+        this.checkProperty("loggerName", "a.B", compact, str, true);
+    }
+
+    @Test
+    public void testContentType() {
+        final AbstractJacksonLayout layout = YamlLayout.createDefaultLayout();
+        assertEquals("application/yaml; charset=UTF-8", layout.getContentType());
+    }
+
+    @Test
+    public void testDefaultCharset() {
+        final AbstractJacksonLayout layout = YamlLayout.createDefaultLayout();
+        assertEquals(StandardCharsets.UTF_8, layout.getCharset());
+    }
+
+    @Test
+    public void testEscapeLayout() throws Exception {
+        final Map<String, Appender> appenders = this.rootLogger.getAppenders();
+        for (final Appender appender : appenders.values()) {
+            this.rootLogger.removeAppender(appender);
+        }
+        final Configuration configuration = rootLogger.getContext().getConfiguration();
+        // set up appender
+        final AbstractJacksonLayout layout = YamlLayout.createLayout(configuration, true, true, null, null, null);
+        final ListAppender appender = new ListAppender("List", null, layout, true, false);
+        appender.start();
+
+        // set appender on root and set level to debug
+        this.rootLogger.addAppender(appender);
+        this.rootLogger.setLevel(Level.DEBUG);
+
+        // output starting message
+        this.rootLogger.debug("Here is a quote ' and then a double quote \"");
+
+        appender.stop();
+
+        final List<String> list = appender.getMessages();
+
+        this.checkAt("---", 0, list);
+        this.checkContains("level: \"DEBUG\"", list);
+        this.checkContains("message: \"Here is a quote ' and then a double quote \\\"\"", list);
+        this.checkContains("loggerFqcn: \"" + AbstractLogger.class.getName() + "\"", list);
+        for (final Appender app : appenders.values()) {
+            this.rootLogger.addAppender(app);
+        }
+    }
+
+    /**
+     * Test case for MDC conversion pattern.
+     */
+    @Test
+    public void testLayout() throws Exception {
+        final Map<String, Appender> appenders = this.rootLogger.getAppenders();
+        for (final Appender appender : appenders.values()) {
+            this.rootLogger.removeAppender(appender);
+        }
+        final Configuration configuration = rootLogger.getContext().getConfiguration();
+        // set up appender
+        // Use [[ and ]] to test header and footer (instead of [ and ])
+        final AbstractJacksonLayout layout = YamlLayout.createLayout(configuration, true, true, "[[", "]]", null);
+        final ListAppender appender = new ListAppender("List", null, layout, true, false);
+        appender.start();
+
+        // set appender on root and set level to debug
+        this.rootLogger.addAppender(appender);
+        this.rootLogger.setLevel(Level.DEBUG);
+
+        // output starting message
+        this.rootLogger.debug("starting mdc pattern test");
+
+        this.rootLogger.debug("empty mdc");
+
+        ThreadContext.put("key1", "value1");
+        ThreadContext.put("key2", "value2");
+
+        this.rootLogger.debug("filled mdc");
+
+        ThreadContext.remove("key1");
+        ThreadContext.remove("key2");
+
+        this.rootLogger.error("finished mdc pattern test", new NullPointerException("test"));
+
+        appender.stop();
+
+        final List<String> list = appender.getMessages();
+
+        this.checkAt("---", 0, list);
+        this.checkContains("loggerFqcn: \"" + AbstractLogger.class.getName() + "\"", list);
+        this.checkContains("level: \"DEBUG\"", list);
+        this.checkContains("message: \"starting mdc pattern test\"", list);
+        for (final Appender app : appenders.values()) {
+            this.rootLogger.addAppender(app);
+        }
+    }
+
+    @Test
+    public void testLayoutLoggerName() throws Exception {
+        final AbstractJacksonLayout layout = YamlLayout.createLayout(null, false, false, null, null,
+                StandardCharsets.UTF_8);
+        final Log4jLogEvent expected = Log4jLogEvent.newBuilder() //
+                .setLoggerName("a.B") //
+                .setLoggerFqcn("f.q.c.n") //
+                .setLevel(Level.DEBUG) //
+                .setMessage(new SimpleMessage("M")) //
+                .setThreadName("threadName") //
+                .setTimeMillis(1).build();
+        final String str = layout.toSerializable(expected);
+        assertTrue(str, str.contains("loggerName: \"a.B\""));
+        final Log4jLogEvent actual = new Log4jYamlObjectMapper().readValue(str, Log4jLogEvent.class);
+        assertEquals(expected.getLoggerName(), actual.getLoggerName());
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testLocationOffCompactOffMdcOff() throws Exception {
+        this.testAllFeatures(false, false, false, false);
+    }
+
+    @Test
+    public void testLocationOnCompactOffEventEolOffMdcOn() throws Exception {
+        this.testAllFeatures(true, false, false, true);
+    }
+
+    private String toPropertySeparator(final boolean compact, final boolean value) {
+        return value ? ": " : ":";
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80a43988/log4j-web/src/main/java/org/apache/logging/log4j/web/ServletRequestThreadContext.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/ServletRequestThreadContext.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/ServletRequestThreadContext.java
new file mode 100644
index 0000000..6615531
--- /dev/null
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/ServletRequestThreadContext.java
@@ -0,0 +1,29 @@
+package org.apache.logging.log4j.web;
+
+import java.util.Objects;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.logging.log4j.ThreadContext;
+
+public class ServletRequestThreadContext {
+
+    public static void put(String key, ServletRequest servletRequest) {
+        put(key, "RemoteAddr", servletRequest.getRemoteAddr());
+        put(key, "RemoteHost", servletRequest.getRemoteHost());
+        put(key, "RemotePort", servletRequest.getRemotePort());
+    }
+
+    public static void put(String key, String field, Object value) {
+        put(key + "." + field, Objects.toString(value));
+    }
+
+    public static void put(String key, String value) {
+        ThreadContext.put(key, value);
+    }
+
+    public static void put(String key, HttpServletRequest servletRequest) {
+        put(key, (ServletRequest) servletRequest);
+    }
+}