Repository: logging-log4j2
Updated Branches:
  refs/heads/master 2ea183ee7 -> 7a6c356d0


LOG4J2-2143 Add missing converters to PatternLayout


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

Branch: refs/heads/master
Commit: 7a6c356d0e898822b4da8fc1cc3dcc9ac59f5cff
Parents: 2ea183e
Author: Mikael Ståldal <mik...@staldal.nu>
Authored: Wed Dec 6 22:11:54 2017 +0100
Committer: Mikael Ståldal <mik...@staldal.nu>
Committed: Wed Dec 6 22:11:54 2017 +0100

----------------------------------------------------------------------
 .../pattern/EndOfBatchPatternConverter.java     | 63 ++++++++++++++++++++
 .../pattern/LoggerFqcnPatternConverter.java     | 63 ++++++++++++++++++++
 .../pattern/EndOfBatchPatternConverterTest.java | 47 +++++++++++++++
 .../pattern/LoggerFqcnPatternConverterTest.java | 38 ++++++++++++
 .../log4j/core/pattern/PatternParserTest.java   | 10 ++++
 src/changes/changes.xml                         |  3 +
 src/site/xdoc/manual/layouts.xml.vm             | 14 +++++
 7 files changed, 238 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverter.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverter.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverter.java
new file mode 100644
index 0000000..a2f95fd
--- /dev/null
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.pattern;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.util.PerformanceSensitive;
+
+/**
+ * Formats the EndOfBatch.
+ *
+ * @since 2.10.1
+ */
+@Plugin(name = "EndOfBatchPatternConverter", category = 
PatternConverter.CATEGORY)
+@ConverterKeys({ "endOfBatch" })
+@PerformanceSensitive("allocation")
+public final class EndOfBatchPatternConverter extends LogEventPatternConverter 
{
+    /**
+     * Singleton.
+     */
+    private static final EndOfBatchPatternConverter INSTANCE =
+        new EndOfBatchPatternConverter();
+
+    /**
+     * Private constructor.
+     */
+    private EndOfBatchPatternConverter() {
+        super("LoggerFqcn", "loggerFqcn");
+    }
+
+    /**
+     * Obtains an instance of EndOfBatchPatternConverter.
+     *
+     * @param options options, currently ignored, may be null.
+     * @return instance of EndOfBatchPatternConverter.
+     */
+    public static EndOfBatchPatternConverter newInstance(
+        final String[] options) {
+        return INSTANCE;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void format(final LogEvent event, final StringBuilder toAppendTo) {
+        toAppendTo.append(event.isEndOfBatch());
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverter.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverter.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverter.java
new file mode 100644
index 0000000..9eb4296
--- /dev/null
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.pattern;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.util.PerformanceSensitive;
+
+/**
+ * Formats the Logger FQCN.
+ *
+ * @since 2.10.1
+ */
+@Plugin(name = "LoggerFqcnPatternConverter", category = 
PatternConverter.CATEGORY)
+@ConverterKeys({ "fqcn" })
+@PerformanceSensitive("allocation")
+public final class LoggerFqcnPatternConverter extends LogEventPatternConverter 
{
+    /**
+     * Singleton.
+     */
+    private static final LoggerFqcnPatternConverter INSTANCE =
+        new LoggerFqcnPatternConverter();
+
+    /**
+     * Private constructor.
+     */
+    private LoggerFqcnPatternConverter() {
+        super("LoggerFqcn", "loggerFqcn");
+    }
+
+    /**
+     * Obtains an instance of LoggerFqcnPatternConverter.
+     *
+     * @param options options, currently ignored, may be null.
+     * @return instance of LoggerFqcnPatternConverter.
+     */
+    public static LoggerFqcnPatternConverter newInstance(
+        final String[] options) {
+        return INSTANCE;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void format(final LogEvent event, final StringBuilder toAppendTo) {
+        toAppendTo.append(event.getLoggerFqcn());
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverterTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverterTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverterTest.java
new file mode 100644
index 0000000..210b689
--- /dev/null
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/EndOfBatchPatternConverterTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.pattern;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class EndOfBatchPatternConverterTest {
+
+    @Test
+    public void testConverterTrue() {
+        final LogEvent event = Log4jLogEvent.newBuilder()
+                .setEndOfBatch(true).build();
+        final StringBuilder sb = new StringBuilder();
+        final LogEventPatternConverter converter = 
EndOfBatchPatternConverter.newInstance(null);
+        converter.format(event, sb);
+        assertEquals("true", sb.toString());
+    }
+
+    @Test
+    public void testConverterFalse() {
+        final LogEvent event = Log4jLogEvent.newBuilder()
+                .build();
+        final StringBuilder sb = new StringBuilder();
+        final LogEventPatternConverter converter = 
EndOfBatchPatternConverter.newInstance(null);
+        converter.format(event, sb);
+        assertEquals("false", sb.toString());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverterTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverterTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverterTest.java
new file mode 100644
index 0000000..2cb1faf
--- /dev/null
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/LoggerFqcnPatternConverterTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.pattern;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class LoggerFqcnPatternConverterTest {
+
+    private static final String FQCN = "com.acme.TheClass";
+
+    @Test
+    public void testConverter() {
+        final LogEvent event = Log4jLogEvent.newBuilder()
+                .setLoggerFqcn(FQCN).build();
+        final StringBuilder sb = new StringBuilder();
+        final LogEventPatternConverter converter = 
LoggerFqcnPatternConverter.newInstance(null);
+        converter.format(event, sb);
+        assertEquals(FQCN, sb.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
index da93afe..a1dec10 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
@@ -272,6 +272,16 @@ public class PatternParserTest {
         testThreadPriorityPattern("%threadPriority");
     }
 
+    @Test
+    public void testLoggerFqcnPattern() {
+        testFirstConverter("%fqcn", LoggerFqcnPatternConverter.class);
+    }
+
+    @Test
+    public void testEndOfBatchPattern() {
+        testFirstConverter("%endOfBatch", EndOfBatchPatternConverter.class);
+    }
+
     private void testThreadIdPattern(final String pattern) {
         testFirstConverter(pattern, ThreadIdPatternConverter.class);
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d37b975..ef2e39e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
          - "remove" - Removed
     -->
     <release version="2.10.1" date="2017-xx-xx" description="GA Release 
2.10.1">
+      <action issue="LOG4J2-2143" dev="mikes" type="add">
+        Add missing converters to PatternLayout.
+      </action>
       <action issue="LOG4J2-2127" dev="rpopma" type="update" due-to="Carter 
Kozak">
         Removed unnecessary threadlocal StringBuilder field from 
MdcPatternConverter.
       </action>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7a6c356d/src/site/xdoc/manual/layouts.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/layouts.xml.vm 
b/src/site/xdoc/manual/layouts.xml.vm
index 3cfab4a..3e8e2a5 100644
--- a/src/site/xdoc/manual/layouts.xml.vm
+++ b/src/site/xdoc/manual/layouts.xml.vm
@@ -1595,6 +1595,20 @@ WARN  [main]: Message 2</pre>
             </tr>
             <tr>
               <td align="center">
+                <a name="PatternLoggerFqcn"/>
+                <b>fqcn</b>
+              </td>
+              <td>Outputs the fully qualified class name of the logging 
event.</td>
+            </tr>
+            <tr>
+              <td align="center">
+                <a name="PatternLoggerFqcn"/>
+                <b>endOfBatch</b>
+              </td>
+              <td>Outputs the EndOfBatch status of the logging event, as 
"true" or "false".</td>
+            </tr>
+            <tr>
+              <td align="center">
                 <a name="PatternNDC"/>
                 <b>x</b><br />
                 <b>NDC</b>

Reply via email to