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/03/11 15:23:30 UTC

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

Repository: logging-log4j2
Updated Branches:
  refs/heads/gelf-layout-gc-free a2b5ed02f -> a5b00b331


LOG4J2-1133 - Add JNDI lookup documentation.


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

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

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


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

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


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

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

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

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

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


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

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


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

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


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

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

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


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


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

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

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

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

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


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

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

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


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

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

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

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

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


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

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

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

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


[21/21] logging-log4j2 git commit: Merge branch 'master' into gelf-layout-gc-free

Posted by mi...@apache.org.
Merge branch 'master' into gelf-layout-gc-free


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

Branch: refs/heads/gelf-layout-gc-free
Commit: a5b00b331330cd8993e037d55a7c1a6001215d53
Parents: a2b5ed0 e2a8652
Author: Mikael Ståldal <mi...@magine.com>
Authored: Fri Mar 11 15:23:10 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Fri Mar 11 15:23:10 2016 +0100

----------------------------------------------------------------------
 log4j-1.2-api/pom.xml                           |   5 +
 .../config/Log4j1ConfigurationFactory.java      | 314 +++++++++++++++++++
 .../config/Log4j1ConfigurationFactoryTest.java  |  88 ++++++
 ...g4j-console-EnhancedPatternLayout.properties |  19 ++
 .../log4j-console-HtmlLayout.properties         |  18 ++
 .../log4j-console-PatternLayout.properties      |  19 ++
 .../log4j-console-SimpleLayout.properties       |  18 ++
 .../log4j-console-TTCCLayout.properties         |  18 ++
 .../log4j-console-XmlLayout.properties          |  18 ++
 .../logging/log4j/core/LoggerContext.java       |   2 +
 .../core/async/AsyncLoggerConfigDisruptor.java  |   4 +-
 .../log4j/core/async/AsyncLoggerDisruptor.java  |   4 +-
 .../logging/log4j/core/lookup/JndiLookup.java   |   2 +-
 .../pattern/EqualsReplacementConverter.java     |  48 ++-
 .../logging/log4j/core/LoggerUpdateTest.java    |  15 +
 .../rolling/RollingAppenderSizeTest.java        |  15 +-
 .../log4j/core/layout/PatternLayoutTest.java    |  22 ++
 .../log4j/core/lookup/JndiLookupTest.java       |  18 ++
 .../pattern/EqualsReplacementConverterTest.java |  63 +++-
 .../apache/logging/log4j/core/util/Compare.java | 134 --------
 .../log4j/web/Log4jWebInitializerImpl.java      |   5 +-
 .../log4j/web/appender/ServletAppender.java     |   4 +-
 src/changes/changes.xml                         |  17 +-
 src/site/xdoc/manual/configuration.xml.vm       |   4 +
 24 files changed, 696 insertions(+), 178 deletions(-)
----------------------------------------------------------------------



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

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


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

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

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


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

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

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


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

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


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

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

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


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


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

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


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

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

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


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


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

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

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

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

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


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

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

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


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

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


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

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

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


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


[19/21] 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/1ecc28bb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1ecc28bb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1ecc28bb

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

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



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

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

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

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

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


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

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

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

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

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


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

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


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

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

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



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

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


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

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

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


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

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

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


[17/21] logging-log4j2 git commit: Remove unused test support class.

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


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

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

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


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


[12/21] 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/9a01ec66
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/9a01ec66
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/9a01ec66

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

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



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

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


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

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

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


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

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


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

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


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

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

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


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

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

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

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


[16/21] logging-log4j2 git commit: Format nit.

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


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

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

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


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


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

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

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


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

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

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


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