logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1545905 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/layout/ log4j-core/src/main/resources/ log4j-core/src/test/java/org/apache/logging/log4j/core/layout/ src/changes/ src/site/xdoc/manual/
Date Wed, 27 Nov 2013 01:58:48 GMT
Author: ggregory
Date: Wed Nov 27 01:58:48 2013
New Revision: 1545905

URL: http://svn.apache.org/r1545905
Log:
[LOG4J2-447] XMLLayout does not include marker name. Apply patch with changes, and also adjust
layout documentation to fix element name casing.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd
    logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.xsd
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml
    logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
Wed Nov 27 01:58:48 2013
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
@@ -195,6 +196,28 @@ public class XMLLayout extends AbstractS
             buf.append(this.eol);
         }
 
+        if (event.getMarker() != null) {
+            final Marker marker = event.getMarker();
+            buf.append(this.indent2);
+            buf.append('<');
+            if (!complete) {
+                buf.append(this.namespacePrefix);
+            }
+            buf.append("Marker");
+            final Marker parent = marker.getParent();
+            if (parent != null) {
+                buf.append(" parent=\"").append(Transform.escapeHtmlTags(parent.getName())).append("\"");
+            }
+            buf.append('>');
+            buf.append(Transform.escapeHtmlTags(marker.getName()));
+            buf.append("</");
+            if (!complete) {
+                buf.append(this.namespacePrefix);
+            }
+            buf.append("Marker>");
+            buf.append(this.eol);
+        }
+
         final Throwable throwable = event.getThrown();
         if (throwable != null) {
             final List<String> s = Throwables.toStringList(throwable);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.dtd Wed Nov 27 01:58:48
2013
@@ -28,6 +28,10 @@
 <!ENTITY % log4j..Events "%log4j_prefix..;Events">
 <!ENTITY % log4j..Event "%log4j_prefix..;Event">
 <!ENTITY % log4j..Message "%log4j_prefix..;Message">
+<!ENTITY % log4j..Marker "%log4j_prefix..;Marker">
+<!ATTLIST %log4j..Marker;
+    parent CDATA #IMPLIED
+>
 <!ENTITY % log4j..NDC "%log4j_prefix..;NDC">
 <!ENTITY % log4j..Throwable "%log4j_prefix..;Throwable">
 <!ENTITY % log4j..LocationInfo "%log4j_prefix..;LocationInfo">
@@ -39,7 +43,7 @@
 <!ATTLIST %log4j..Events;
 	%documentElementAttributes;
 >
-<!ELEMENT %log4j..Event; (%log4j..Message;, (%log4j..NDC;)?, (%log4j..Throwable;)?, (%log4j..LocationInfo;)?,
(%log4j..Properties;)?)>
+<!ELEMENT %log4j..Event; (%log4j..Message;, (%log4j..NDC;)?, (%log4j..Marker;)?, (%log4j..Throwable;)?,
(%log4j..LocationInfo;)?, (%log4j..Properties;)?)>
 <!ATTLIST %log4j..Event;
 	logger CDATA #REQUIRED
 	timestamp NMTOKEN #REQUIRED

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.xsd
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.xsd?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.xsd (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/resources/Log4j-events.xsd Wed Nov 27 01:58:48
2013
@@ -28,6 +28,11 @@
                         <xs:sequence>
                             <xs:element name="Message"/>
                             <xs:element name="NDC" minOccurs="0"/>
+                            <xs:element name="Marker" minOccurs="0">
+                               <xs:complexType mixed="true">
+                                   <xs:attribute name="parent" type="xs:string" use="optional"/>
+                               </xs:complexType>
+                           </xs:element>
                             <xs:element name="Throwable" minOccurs="0"/>
                             <xs:element name="LocationInfo" minOccurs="0">
                                 <xs:complexType>

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
Wed Nov 27 01:58:48 2013
@@ -16,29 +16,32 @@
  */
 package org.apache.logging.log4j.core.layout;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.BasicConfigurationFactory;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.helpers.Charsets;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 /**
  *
  */
 public class XMLLayoutTest {
     private static final String body = "<Message><![CDATA[empty mdc]]></Message>";
+    private static final String markerTag = "<Marker>EVENT</Marker>";
     static ConfigurationFactory cf = new BasicConfigurationFactory();
 
     @AfterClass
@@ -99,6 +102,9 @@ public class XMLLayoutTest {
 
         root.error("finished mdc pattern test", new NullPointerException("test"));
 
+        final Marker marker = MarkerManager.getMarker("EVENT");
+        root.error(marker, "marker test");
+
         appender.stop();
 
         final List<String> list = appender.getMessages();
@@ -108,5 +114,8 @@ public class XMLLayoutTest {
         assertTrue("Incorrect header: " + string, string.equals("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>"));
         assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</Events>"));
         assertTrue("Incorrect body. Expected " + body + " Actual: " + list.get(7), list.get(7).trim().equals(body));
+
+        assertTrue("Missing Marker-Tag, Expected "+markerTag+", Actual"+list.get(list.size()
- 4),
+                   list.get(list.size() - 4).contains(markerTag));
     }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Nov 27 01:58:48 2013
@@ -20,7 +20,10 @@
     <title>Changes</title>
   </properties>
   <body>
-    <release version="2.0RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+    <release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-447" dev="ggregory" type="fix" due-to="Jeff Hudren, Mark Paluch,
Scott Deboy">
+        XMLLayout does not include marker name.
+      </action>
       <action issue="LOG4J2-453" dev="rgoers" type="update">
         Update Flume Appender to use Flume 1.4.0.
       </action>

Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm?rev=1545905&r1=1545904&r2=1545905&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/layouts.xml.vm Wed Nov 27 01:58:48 2013
@@ -1309,7 +1309,7 @@ at org.apache.logging.log4j.core.pattern
         <subsection name="XMLLayout">
           <!-- From Javadoc of org.apache.logging.log4j.core.layout.XMLLayout -->
           <p>
-          Appends a series of <code>event</code> elements as defined in the <a
href="log4j.dtd">log4j.dtd</a>.
+          Appends a series of <code>Event</code> elements as defined in the <a
href="log4j.dtd">log4j.dtd</a>.
           </p>
           <h4>Complete well-formed XML vs. fragment XML</h4>
           <p>
@@ -1323,14 +1323,16 @@ at org.apache.logging.log4j.core.pattern
           A well-formed XML document follows this pattern:
           </p>
           <pre class="prettyprint linenums">&lt;?xml version=&quot;1.0&quot;
encoding=&quot;UTF-8&quot;?&gt;
-&lt;events xmlns=&quot;http://logging.apache.org/log4j/2.0/events&quot;&gt;
-  &lt;event logger=&quot;com.foo.Bar&quot; timestamp=&quot;1373436580419&quot;
level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
-    &lt;message&gt;&lt;![CDATA[This is a log message 1]]&gt;&lt;/message&gt;
-  &lt;/event&gt;
-  &lt;event logger=&quot;com.foo.Baz&quot; timestamp=&quot;1373436580420&quot;
level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
-    &lt;message&gt;&lt;![CDATA[This is a log message 2]]&gt;&lt;/message&gt;
-  &lt;/event&gt;
-&lt;/events&gt;</pre>
+&lt;Events xmlns=&quot;http://logging.apache.org/log4j/2.0/events&quot;&gt;
+  &lt;Event logger=&quot;com.foo.Bar&quot; timestamp=&quot;1373436580419&quot;
level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
+    &lt;Message&gt;&lt;![CDATA[This is a log message 1]]&gt;&lt;/Message&gt;
+    &lt;Marker parent=&quot;Parent Marker&quot;&gt;&lt;Child Marker&gt;&lt;/Marker&gt;
+  &lt;/Event&gt;
+  &lt;Event logger=&quot;com.foo.Baz&quot; timestamp=&quot;1373436580420&quot;
level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
+    &lt;Message&gt;&lt;![CDATA[This is a log message 2]]&gt;&lt;/Message&gt;
+    &lt;Marker&gt;&lt;The Marker Name&gt;&lt;/Marker&gt;
+  &lt;/Event&gt;
+&lt;/Events&gt;</pre>
           <p>
           If <code>complete="false"</code>, the appender does not write the XML
processing instruction and the root 
           element.
@@ -1338,6 +1340,12 @@ at org.apache.logging.log4j.core.pattern
           <p>
           This approach enforces the independence of the XMLLayout and the appender where
you embed it.
           </p>
+          <h4>Marker</h4>
+          <p>Markers are represented by a <code>Marker</code> element within
the <code>Event</code> element.
+          The <code>Marker</code> element appears only when a marker is used
in the log message. The name of the marker's
+          parent will be provided in the <code>parent</code> attribute of the
<code>Marker</code> element.
+          Only the leaf marker is included, not the full hierarchy.
+          </p>
           <h4>Encoding</h4>
           <p>
           Appenders using this layout should have their <code>charset</code>
set to <code>UTF-8</code> or 



Mime
View raw message