logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1504299 - in /logging/log4j/log4j2/trunk/core/src: main/java/org/apache/logging/log4j/core/layout/ main/resources/ test/java/org/apache/logging/log4j/core/appender/ test/java/org/apache/logging/log4j/core/layout/ test/resources/
Date Wed, 17 Jul 2013 22:03:19 GMT
Author: ggregory
Date: Wed Jul 17 22:03:19 2013
New Revision: 1504299

URL: http://svn.apache.org/r1504299
Log:
- Use CamelCase for element names, like class names.
- Use camelCase of attribute names, like instance variables.
- Add first cut of DTD for XML layout.
- Add first cut of XSD for XML layout.
- Remove trailing ‘/’ at the end of the namespace.

Added:
    logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd   (with props)
    logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
  (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
  (with props)
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
    logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderTest.xml
    logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompleteFileAppenderTest.xml
    logging/log4j/log4j2/trunk/core/src/test/resources/XmlFileAppenderTest.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
Wed Jul 17 22:03:19 2013
@@ -55,14 +55,14 @@ import org.apache.logging.log4j.message.
  * 
  * <pre>
  * &lt;?xml version="1.0" encoding=&quotUTF-8&quot?&gt;
- * &lt;events xmlns="http://logging.apache.org/log4j/2.0"&gt;
- * &nbsp;&nbsp;&lt;event logger="com.foo.Bar" timestamp="1373436580419" level="INFO"
thread="main"&gt;
- * &nbsp;&nbsp;&nbsp;&nbsp;&lt;message>&lt;![CDATA[This is a log
message 1]]&gt;&lt;/message&gt;
- * &nbsp;&nbsp;&lt;/event&gt;
- * &nbsp;&nbsp;&lt;event logger="com.foo.Baz" timestamp="1373436580420" level="INFO"
thread="main"&gt;
- * &nbsp;&nbsp;&nbsp;&nbsp;&lt;message>&lt;![CDATA[This is a log
message 2]]&gt;&lt;/message&gt;
- * &nbsp;&nbsp;&lt;/event&gt;
- * &lt;/events&gt;
+ * &lt;Events xmlns="http://logging.apache.org/log4j/2.0"&gt;
+ * &nbsp;&nbsp;&lt;Event logger="com.foo.Bar" timestamp="1373436580419" level="INFO"
thread="main"&gt;
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;Message>&lt;![CDATA[This is a log
message 1]]&gt;&lt;/Message&gt;
+ * &nbsp;&nbsp;&lt;/Event&gt;
+ * &nbsp;&nbsp;&lt;Event logger="com.foo.Baz" timestamp="1373436580420" level="INFO"
thread="main"&gt;
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;Message>&lt;![CDATA[This is a log
message 2]]&gt;&lt;/Message&gt;
+ * &nbsp;&nbsp;&lt;/Event&gt;
+ * &lt;/Events&gt;
  * </pre>
  * <p>
  * If {@code complete="false"}, the appender does not write the XML processing instruction
and the root element.
@@ -85,7 +85,8 @@ import org.apache.logging.log4j.message.
 @Plugin(name = "XMLLayout", category = "Core", elementType = "layout", printObject = true)
 public class XMLLayout extends AbstractStringLayout {
 
-    private static final String XML_NAMESPACE = "http://logging.apache.org/log4j/2.0/";
+    private static final String XML_NAMESPACE = "http://logging.apache.org/log4j/2.0";
+    private static final String ROOT_TAG = "Events";
     private static final int DEFAULT_SIZE = 256;
     
     // We yield to \r\n for the default.
@@ -134,7 +135,7 @@ public class XMLLayout extends AbstractS
         if (!complete) {
             buf.append(this.namespacePrefix);
         }
-        buf.append("event logger=\"");
+        buf.append("Event logger=\"");
         String name = event.getLoggerName();
         if (name.isEmpty()) {
             name = "root";
@@ -166,7 +167,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("message>");
+            buf.append("Message>");
             if (xmlSupported) {
                 buf.append(((MultiformatMessage) msg).getFormattedMessage(FORMATS));
             } else {
@@ -180,7 +181,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("message>");
+            buf.append("Message>");
             buf.append(this.eol);
         }
 
@@ -208,7 +209,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("throwable><![CDATA[");
+            buf.append("Throwable><![CDATA[");
             for (final String str : s) {
                 Transform.appendEscapingCDATA(buf, str);
                 buf.append(this.eol);
@@ -217,7 +218,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("throwable>");
+            buf.append("Throwable>");
             buf.append(this.eol);
         }
 
@@ -228,7 +229,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("locationInfo class=\"");
+            buf.append("LocationInfo class=\"");
             buf.append(Transform.escapeTags(element.getClassName()));
             buf.append("\" method=\"");
             buf.append(Transform.escapeTags(element.getMethodName()));
@@ -246,7 +247,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("properties>");
+            buf.append("Properties>");
             buf.append(this.eol);
             for (final Map.Entry<String, String> entry : event.getContextMap().entrySet())
{
                 buf.append(this.indent3);
@@ -254,7 +255,7 @@ public class XMLLayout extends AbstractS
                 if (!complete) {
                     buf.append(this.namespacePrefix);
                 }
-                buf.append("data name=\"");
+                buf.append("Data name=\"");
                 buf.append(Transform.escapeTags(entry.getKey()));
                 buf.append("\" value=\"");
                 buf.append(Transform.escapeTags(String.valueOf(entry.getValue())));
@@ -266,7 +267,7 @@ public class XMLLayout extends AbstractS
             if (!complete) {
                 buf.append(this.namespacePrefix);
             }
-            buf.append("properties>");
+            buf.append("Properties>");
             buf.append(this.eol);
         }
 
@@ -275,7 +276,7 @@ public class XMLLayout extends AbstractS
         if (!complete) {
             buf.append(this.namespacePrefix);
         }
-        buf.append("event>");
+        buf.append("Event>");
         buf.append(this.eol);
 
         return buf.toString();
@@ -301,7 +302,9 @@ public class XMLLayout extends AbstractS
         buf.append("\"?>");
         buf.append(this.eol);
         // Make the log4j namespace the default namespace, no need to use more space with
a namespace prefix.
-        buf.append("<events xmlns=\"" + XML_NAMESPACE + "\">");
+        buf.append('<');
+        buf.append(ROOT_TAG);
+        buf.append(" xmlns=\"" + XML_NAMESPACE + "\">");
         buf.append(this.eol);
         return buf.toString().getBytes(this.getCharset());
     }
@@ -317,19 +320,20 @@ public class XMLLayout extends AbstractS
         if (!complete) {
             return null;
         }
-        return ("</events>" + this.eol).getBytes(getCharset());
+        return ("</" + ROOT_TAG + ">" + this.eol).getBytes(getCharset());
     }
 
     /**
      * XMLLayout's content format is specified by:<p/>
-     * Key: "dtd" Value: "log4j.dtd"<p/>
+     * Key: "dtd" Value: "log4j-events.dtd"<p/>
      * Key: "version" Value: "2.0"
      * @return Map of content format keys supporting XMLLayout
      */
     @Override
     public Map<String, String> getContentFormat() {
         final Map<String, String> result = new HashMap<String, String>();
-        result.put("dtd", "log4j.dtd");
+        //result.put("dtd", "log4j-events.dtd");
+        result.put("xsd", "log4j-events.xsd");
         result.put("version", "2.0");
         return result;
     }

Added: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd?rev=1504299&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd (added)
+++ logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd Wed Jul 17 22:03:19
2013
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--DTD generated by XMLSpy v2011 rel. 3 sp1 (x64) (http://www.altova.com)-->
+<!--the entity declarations may be overridden in the internal subset-->
+<!--namespace prefixes-->
+<!ENTITY % log4j_prefix "log4j">
+<!--namespace prefix to namespace uri mappings-->
+<!ENTITY % log4j_prefix.. "%log4j_prefix;:">
+<!--namespaces attributes for root element-->
+<!ENTITY % documentElementAttributes " xmlns:%log4j_prefix; CDATA 'http://logging.apache.org/log4j/2.0'">
+<!--the declarations below should not be modified-->
+<!--element name mappings-->
+<!ENTITY % log4j..Events "%log4j_prefix..;Events">
+<!ENTITY % log4j..Event "%log4j_prefix..;Event">
+<!ENTITY % log4j..Message "%log4j_prefix..;Message">
+<!ENTITY % log4j..NDC "%log4j_prefix..;NDC">
+<!ENTITY % log4j..Throwable "%log4j_prefix..;Throwable">
+<!ENTITY % log4j..LocationInfo "%log4j_prefix..;LocationInfo">
+<!ENTITY % log4j..Properties "%log4j_prefix..;Properties">
+<!ENTITY % log4j..Data "%log4j_prefix..;Data">
+<!--element and attribute declarations-->
+<!--Log4J 2.0 XML Schema-->
+<!ELEMENT %log4j..Events; ((%log4j..Event;)*)>
+<!ATTLIST %log4j..Events;
+	%documentElementAttributes;
+>
+<!ELEMENT %log4j..Event; (%log4j..Message;, (%log4j..NDC;)?, (%log4j..Throwable;)?, (%log4j..LocationInfo;)?,
(%log4j..Properties;)?)>
+<!ATTLIST %log4j..Event;
+	logger CDATA #REQUIRED
+	timestamp NMTOKEN #REQUIRED
+	level (OFF | FATAL | ERROR | WARN | INFO | DEBUG | TRACE | ALL) #REQUIRED
+	thread CDATA #REQUIRED
+>
+<!ELEMENT %log4j..Message; ANY>
+<!ELEMENT %log4j..NDC; ANY>
+<!ELEMENT %log4j..Throwable; ANY>
+<!ELEMENT %log4j..LocationInfo; EMPTY>
+<!ATTLIST %log4j..LocationInfo;
+	class CDATA #REQUIRED
+	method CDATA #REQUIRED
+	file CDATA #REQUIRED
+	line NMTOKEN #REQUIRED
+>
+<!ELEMENT %log4j..Properties; ((%log4j..Data;)+)>
+<!ELEMENT %log4j..Data; EMPTY>
+<!ATTLIST %log4j..Data;
+	name CDATA #REQUIRED
+	value CDATA #REQUIRED
+>

Propchange: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.dtd
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd?rev=1504299&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd (added)
+++ logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd Wed Jul 17 22:03:19
2013
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- edited with XMLSpy v2011 rel. 3 sp1 (x64) (http://www.altova.com) by Gary Gregory
(Rocket Software) -->
+<!--
+ 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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:log4j="http://logging.apache.org/log4j/2.0"
targetNamespace="http://logging.apache.org/log4j/2.0" elementFormDefault="qualified" attributeFormDefault="unqualified">
+    <xs:element name="Events">
+        <xs:annotation>
+            <xs:documentation>Log4J 2.0 XML Schema</xs:documentation>
+        </xs:annotation>
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="Event" minOccurs="0" maxOccurs="unbounded">
+                    <xs:complexType>
+                        <xs:sequence>
+                            <xs:element name="Message"/>
+                            <xs:element name="NDC" minOccurs="0"/>
+                            <xs:element name="Throwable" minOccurs="0"/>
+                            <xs:element name="LocationInfo" minOccurs="0">
+                                <xs:complexType>
+                                    <xs:attribute name="class" type="xs:string" use="required"/>
+                                    <xs:attribute name="method" type="xs:string" use="required"/>
+                                    <xs:attribute name="file" type="xs:string" use="required"/>
+                                    <xs:attribute name="line" type="xs:int" use="required"/>
+                                </xs:complexType>
+                            </xs:element>
+                            <xs:element name="Properties" minOccurs="0">
+                                <xs:complexType>
+                                    <xs:sequence>
+                                        <xs:element name="Data" maxOccurs="unbounded">
+                                            <xs:complexType>
+                                                <xs:attribute name="name" type="xs:string"
use="required"/>
+                                                <xs:attribute name="value" use="required"/>
+                                            </xs:complexType>
+                                        </xs:element>
+                                    </xs:sequence>
+                                </xs:complexType>
+                            </xs:element>
+                        </xs:sequence>
+                        <xs:attribute name="logger" type="xs:string" use="required"/>
+                        <xs:attribute name="timestamp" type="xs:long" use="required"/>
+                        <xs:attribute name="level" type="log4j:LevelEnum" use="required"/>
+                        <xs:attribute name="thread" type="xs:string" use="required"/>
+                    </xs:complexType>
+                </xs:element>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+    <xs:simpleType name="LevelEnum">
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="OFF"/>
+            <xs:enumeration value="FATAL"/>
+            <xs:enumeration value="ERROR"/>
+            <xs:enumeration value="WARN"/>
+            <xs:enumeration value="INFO"/>
+            <xs:enumeration value="DEBUG"/>
+            <xs:enumeration value="TRACE"/>
+            <xs:enumeration value="ALL"/>
+        </xs:restriction>
+    </xs:simpleType>
+</xs:schema>

Propchange: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/main/resources/Log4j-events.xsd
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderTest.java
Wed Jul 17 22:03:19 2013
@@ -16,7 +16,8 @@
  */
 package org.apache.logging.log4j.core.appender;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -42,30 +43,29 @@ public class XmlCompactFileAppenderTest 
 
     @Test
     public void testFlushAtEndOfBatch() throws Exception {
-        final File f = new File("target", "XmlCompactFileAppenderTest.log");
-        // System.out.println(f.getAbsolutePath());
-        f.delete();
+        final File file = new File("target", "XmlCompactFileAppenderTest.log");
+        file.delete();
         final Logger log = LogManager.getLogger("com.foo.Bar");
         final String logMsg = "Message flushed with immediate flush=false";
         log.info(logMsg);
         ((LifeCycle) LogManager.getContext()).stop(); // stop async thread
 
-        final BufferedReader reader = new BufferedReader(new FileReader(f));
+        final BufferedReader reader = new BufferedReader(new FileReader(file));
         String line1;
         try {
             line1 = reader.readLine();
         } finally {
             reader.close();
-            f.delete();
+            file.delete();
         }
         assertNotNull("line1", line1);
         final String msg1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
         assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + "]",
line1.contains(msg1));
 
-        final String msg2 = "<events xmlns=\"http://logging.apache.org/log4j/2.0/\">";
+        final String msg2 = "<Events xmlns=\"http://logging.apache.org/log4j/2.0\">";
         assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg2 + "]",
line1.contains(msg2));
 
-        final String msg3 = "<event ";
+        final String msg3 = "<Event ";
         assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg3 + "]",
line1.contains(msg3));
 
         final String msg4 = logMsg;
@@ -77,4 +77,5 @@ public class XmlCompactFileAppenderTest 
         assertTrue(line1.indexOf('\r') == -1);
         assertTrue(line1.indexOf('\n') == -1);
     }
+    
 }

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java?rev=1504299&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
(added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
Wed Jul 17 22:03:19 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LifeCycle;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests XML validation for a "compact" XML file, no extra spaces or end of lines.
+ */
+@Ignore
+public class XmlCompactFileAppenderValidationTest {
+
+    @BeforeClass
+    public static void beforeClass() {
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, 
+                "XmlCompactFileAppenderValidationTest.xml");
+    }
+
+    @Test
+    public void validateXmlSchema() throws Exception {
+        final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml");
+        file.delete();
+        final Logger log = LogManager.getLogger("com.foo.Bar");
+        log.warn("Message 1");
+        log.info("Message 2");
+        log.debug("Message 3");
+        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread
+        this.validateXmlSchema(file);
+    }
+
+    @Test
+    public void validateXmlNoEvents() throws Exception {
+        final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml");
+        file.delete();
+        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread
+        this.validateXmlSchema(file);
+    }
+
+    private void validateXmlSchema(File file) throws SAXException, IOException {
+        final URL schemaFile = this.getClass().getClassLoader().getResource("Log4j-events.xsd");
+        final Source xmlFile = new StreamSource(file);
+        final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        final Schema schema = schemaFactory.newSchema(schemaFile);
+        final Validator validator = schema.newValidator();
+        validator.validate(xmlFile);
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompactFileAppenderValidationTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java
Wed Jul 17 22:03:19 2013
@@ -69,11 +69,11 @@ public class XmlCompleteFileAppenderTest
         assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + "]",
line1.equals(msg1));
         
         assertNotNull("line2", line2);
-        final String msg2 = "<events xmlns=\"http://logging.apache.org/log4j/2.0/\">";
+        final String msg2 = "<Events xmlns=\"http://logging.apache.org/log4j/2.0\">";
         assertTrue("line2 incorrect: [" + line2 + "], does not contain: [" + msg2 + "]",
line2.equals(msg2));
         
         assertNotNull("line3", line3);
-        final String msg3 = "<event ";
+        final String msg3 = "<Event ";
         assertTrue("line3 incorrect: [" + line3 + "], does not contain: [" + msg3 + "]",
line3.contains(msg3));
 
         assertNotNull("line4", line4);

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/XmlFileAppenderTest.java
Wed Jul 17 22:03:19 2013
@@ -65,7 +65,7 @@ public class XmlFileAppenderTest {
         assertNotNull("line1", line1);
         
         assertNotNull("line1", line1);
-        final String msg1 = "<log4j:event ";
+        final String msg1 = "<log4j:Event ";
         assertTrue("line1 incorrect: [" + line1 + "], does not contain: [" + msg1 + "]",
line1.contains(msg1));
 
         assertNotNull("line2", line2);
@@ -73,7 +73,7 @@ public class XmlFileAppenderTest {
         assertTrue("line2 incorrect: [" + line2 + "], does not contain: [" + msg2 + "]",
line2.contains(msg2));
 
         assertNotNull("line3", line3);
-        final String msg3 = "</log4j:event>";
+        final String msg3 = "</log4j:Event>";
         assertTrue("line3 incorrect: [" + line3 + "], does not contain: [" + msg3 + "]",
line3.contains(msg3));
 
         final String location = "testFlushAtEndOfBatch";

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
Wed Jul 17 22:03:19 2013
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertTru
  */
 public class XMLLayoutTest {
     private static final String body =
-        "<message><![CDATA[empty mdc]]></message>";
+        "<Message><![CDATA[empty mdc]]></Message>";
     static ConfigurationFactory cf = new BasicConfigurationFactory();
 
     @AfterClass
@@ -107,7 +107,7 @@ public class XMLLayoutTest {
         assertTrue("Incorrect number of lines. Require at least 50 " + list.size(), list.size()
> 50);
         final String string = list.get(0);
         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 footer", list.get(list.size() - 1).equals("</Events>"));
         assertTrue("Incorrect body. Expected " + body + " Actual: " + list.get(7), list.get(7).trim().equals(body));
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderTest.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderTest.xml?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderTest.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderTest.xml Wed
Jul 17 22:03:19 2013
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration status="OFF">
-  <appenders>
+<Configuration status="ERROR">
+  <Appenders>
     <File name="XmlFile" fileName="target/XmlCompactFileAppenderTest.log" immediateFlush="false"
append="false">
-      <XMLLayout complete="true" compact="true"/>
+      <XMLLayout complete="true" compact="true" charset="UTF-8"/>
     </File>
-  </appenders>
+  </Appenders>
   
-  <loggers>
-    <asyncRoot level="info" includeLocation="false">
-      <appender-ref ref="XmlFile"/>
-    </asyncRoot>
-  </loggers>
-</configuration>
+  <Loggers>
+    <AsyncRoot level="info" includeLocation="false">
+      <Appender-ref ref="XmlFile"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>

Added: logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml?rev=1504299&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
(added)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
Wed Jul 17 22:03:19 2013
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="OFF">
+  <Appenders>
+    <File name="XmlFile" fileName="target/XmlCompactFileAppenderValidationTest.log.xml"
immediateFlush="false" append="false">
+      <XMLLayout complete="true" compact="true" charset="UTF-8"/>
+    </File>
+  </Appenders>
+  
+  <Loggers>
+    <AsyncRoot level="info" includeLocation="false">
+      <appender-ref ref="XmlFile"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>

Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompactFileAppenderValidationTest.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompleteFileAppenderTest.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompleteFileAppenderTest.xml?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompleteFileAppenderTest.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/XmlCompleteFileAppenderTest.xml Wed
Jul 17 22:03:19 2013
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration status="OFF">
-  <appenders>
+<Configuration status="OFF">
+  <Appenders>
     <File name="XmlFile" fileName="target/XmlCompleteFileAppenderTest.log" immediateFlush="false"
append="false">
-      <XMLLayout complete="true"/>
+      <XMLLayout complete="true" charset="UTF-8"/>
     </File>
-  </appenders>
+  </Appenders>
   
-  <loggers>
-    <asyncRoot level="info" includeLocation="false">
-      <appender-ref ref="XmlFile"/>
-    </asyncRoot>
-  </loggers>
-</configuration>
+  <Loggers>
+    <AsyncRoot level="info" includeLocation="false">
+      <Appender-ref ref="XmlFile"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/XmlFileAppenderTest.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/XmlFileAppenderTest.xml?rev=1504299&r1=1504298&r2=1504299&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/XmlFileAppenderTest.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/XmlFileAppenderTest.xml Wed Jul 17
22:03:19 2013
@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration status="OFF">
-  <appenders>
+<Configuration status="OFF">
+  <Appenders>
     <File name="XmlFile" fileName="target/XmlFileAppenderTest.log" immediateFlush="false"
append="false">
-      <XMLLayout/>
+      <XMLLayout charset="UTF-8"/>
     </File>
-  </appenders>
+  </Appenders>
   
-  <loggers>
-    <asyncRoot level="info" includeLocation="false">
-      <appender-ref ref="XmlFile"/>
-    </asyncRoot>
-  </loggers>
-</configuration>
\ No newline at end of file
+  <Loggers>
+    <AsyncRoot level="info" includeLocation="false">
+      <Appender-ref ref="XmlFile"/>
+    </AsyncRoot>
+  </Loggers>
+</Configuration>
\ No newline at end of file



Mime
View raw message