logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1128132 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src: main/java/org/apache/logging/log4j/core/ main/java/org/apache/logging/log4j/core/appender/ main/java/org/apache/logging/log4j/core/layout/ test/java/org/a...
Date Fri, 27 May 2011 01:39:09 GMT
Author: rgoers
Date: Fri May 27 01:39:09 2011
New Revision: 1128132

URL: http://svn.apache.org/viewvc?rev=1128132&view=rev
Log:
Add SerializedLayout. Modify XMLLayout and HTMLLayout to be thread safe.

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
      - copied, changed from r1127788, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/SerializedLayoutTest.java
      - copied, changed from r1127788, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
Fri May 27 01:39:09 2011
@@ -160,6 +160,15 @@ public class Log4jLogEvent implements Lo
         throw new InvalidObjectException("Proxy required");
     }
 
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        String n = name.length() == 0 ? "root" : name;
+        sb.append("Logger=").append(n);
+        sb.append(" Level=").append(level.name());
+        sb.append(" Message").append(message.getFormattedMessage());
+        return sb.toString();
+    }
+
     private static class LogEventProxy implements Serializable {
 
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java
Fri May 27 01:39:09 2011
@@ -25,6 +25,8 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.filter.Filters;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -40,16 +42,22 @@ public class ListAppender extends Append
 
     private List<String> messages = new ArrayList<String>();
 
+    private List<byte[]> data = new ArrayList<byte[]>();
+
     private final boolean newLine;
 
+    private final boolean raw;
+
     public ListAppender(String name) {
         super(name, null, null);
         newLine = false;
+        raw = false;
     }
 
-    public ListAppender(String name, Filters filters, Layout layout, boolean newline) {
+    public ListAppender(String name, Filters filters, Layout layout, boolean newline, boolean
raw) {
         super(name, filters, layout);
         this.newLine = newline;
+        this.raw = raw;
         if (layout != null) {
             byte[] bytes = layout.getHeader();
             if (bytes != null) {
@@ -68,6 +76,10 @@ public class ListAppender extends Append
     }
 
     private void write(byte[] bytes) {
+        if (raw) {
+            data.add(bytes);
+            return;
+        }
         String str = new String(bytes);
         if (newLine) {
             int index = 0;
@@ -114,9 +126,14 @@ public class ListAppender extends Append
         return Collections.unmodifiableList(messages);
     }
 
+    public synchronized List<byte[]> getData() {
+        return Collections.unmodifiableList(data);
+    }
+
     @PluginFactory
     public static ListAppender createAppender(@PluginAttr("name") String name,
                                               @PluginAttr("entryPerNewLine") String newLine,
+                                              @PluginAttr("raw") String raw,
                                               @PluginElement("layout") Layout layout,
                                               @PluginElement("filters") Filters filters)
{
 
@@ -126,7 +143,8 @@ public class ListAppender extends Append
         }
 
         boolean nl = (newLine == null) ? false : Boolean.parseBoolean(newLine);
+        boolean r = (raw == null) ? false : Boolean.parseBoolean(raw);
 
-        return new ListAppender(name, filters, layout, nl);
+        return new ListAppender(name, filters, layout, nl, r);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java
Fri May 27 01:39:09 2011
@@ -42,13 +42,9 @@ import java.util.ArrayList;
 @Plugin(name="HTMLLayout",type="Core",elementType="layout",printObject=true)
 public class HTMLLayout extends LayoutBase {
 
-    protected final int BUF_SIZE = 256;
-    protected final int MAX_CAPACITY = 1024;
+    protected static final int BUF_SIZE = 256;
 
-    static String TRACE_PREFIX = "<br>&nbsp;&nbsp;&nbsp;&nbsp;";
-
-    // output buffer appended to when format() is invoked
-    private StringBuilder sbuf = new StringBuilder(BUF_SIZE);
+    private static final String TRACE_PREFIX = "<br>&nbsp;&nbsp;&nbsp;&nbsp;";
 
     // Print no location info by default
     protected final boolean locationInfo;
@@ -71,12 +67,7 @@ public class HTMLLayout extends LayoutBa
     }
 
     public byte[] format(LogEvent event) {
-
-        if (sbuf.capacity() > MAX_CAPACITY) {
-            sbuf = new StringBuilder(BUF_SIZE);
-        } else {
-            sbuf.setLength(0);
-        }
+        StringBuilder sbuf = new StringBuilder(BUF_SIZE);
 
         sbuf.append(LINE_SEP).append("<tr>").append(LINE_SEP);
 
@@ -85,7 +76,7 @@ public class HTMLLayout extends LayoutBa
         sbuf.append("</td>").append(LINE_SEP);
 
         String escapedThread = Transform.escapeTags(event.getThreadName());
-        sbuf.append("<td title=\"" + escapedThread + " thread\">");
+        sbuf.append("<td title=\"").append(escapedThread).append(" thread\">");
         sbuf.append(escapedThread);
         sbuf.append("</td>").append(LINE_SEP);
 
@@ -128,7 +119,7 @@ public class HTMLLayout extends LayoutBa
         if (event.getContextStack().size() > 0) {
             sbuf.append(
                 "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\"
title=\"Nested Diagnostic Context\">");
-            sbuf.append("NDC: " + Transform.escapeTags(event.getContextStack().toString()));
+            sbuf.append("NDC: ").append(Transform.escapeTags(event.getContextStack().toString()));
             sbuf.append("</td></tr>").append(LINE_SEP);
         }
 
@@ -136,7 +127,7 @@ public class HTMLLayout extends LayoutBa
         if (event.getContextMap().size() > 0) {
             sbuf.append(
                 "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\"
title=\"Mapped Diagnostic Context\">");
-            sbuf.append("MDC: " + Transform.escapeTags(event.getContextMap().toString()));
+            sbuf.append("MDC: ").append(Transform.escapeTags(event.getContextMap().toString()));
             sbuf.append("</td></tr>").append(LINE_SEP);
         }
 

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
(from r1127788, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java&r1=1127788&r2=1128132&rev=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
Fri May 27 01:39:09 2011
@@ -16,9 +16,17 @@
  */
 package org.apache.logging.log4j.core.layout;
 
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttr;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.Transform;
+
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.io.LineNumberReader;
+import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
@@ -27,218 +35,33 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttr;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.helpers.Transform;
-import org.apache.logging.log4j.core.LogEvent;
-
 
 /**
- * The output of the XMLLayout consists of a series of log4j:event
- * elements as defined in the <a href="log4j.dtd">log4j.dtd</a>. If configured
to do so it will
- * output a complete well-formed XML file. The output is designed to be
- * included as an <em>external entity</em> in a separate file to form
- * a correct XML file.
- * <p/>
- * <p>For example, if <code>abc</code> is the name of the file where
- * the XMLLayout ouput goes, then a well-formed XML file would be:
- * <p/>
- * <pre>
- * &lt;?xml version="1.0" ?&gt;
  *
- * &lt;!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd" [&lt;!ENTITY data SYSTEM "abc"&gt;]&gt;
- *
- * &lt;log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/"&gt;
- * &nbsp;&nbsp;&data;
- * &lt;/log4j:eventSet&gt;
- * </pre>
- * <p/>
- * <p>This approach enforces the independence of the XMLLayout and the
- * appender where it is embedded.
- * <p/>
- * <p>The <code>version</code> attribute helps components to correctly
- * intrepret output generated by XMLLayout. The value of this
- * attribute should be "1.1" for output generated by log4j versions
- * prior to log4j 1.2 (final release) and "1.2" for relase 1.2 and
- * later.
- * <p/>
- * Appenders using this layout should have their encoding
- * set to UTF-8 or UTF-16, otherwise events containing
- * non ASCII characters could result in corrupted
- * log files.
  */
-@Plugin(name="XMLLayout",type="Core",elementType="layout",printObject=true)
-public class XMLLayout extends LayoutBase {
-
-    private static final int DEFAULT_SIZE = 256;
-    private static final int UPPER_LIMIT = 2048;
+@Plugin(name="SerializedLayout",type="Core",elementType="layout",printObject=true)
+public class SerializedLayout extends LayoutBase {
 
-    private StringBuilder buf = new StringBuilder(DEFAULT_SIZE);
-    private final boolean locationInfo;
-    private final boolean properties;
-    private final boolean complete;
-
-    protected final Charset charset;
-
-    public XMLLayout(boolean locationInfo, boolean properties, boolean complete, Charset
charset) {
-        this.locationInfo = locationInfo;
-        this.charset = charset;
-        this.properties = properties;
-        this.complete = complete;
+    public SerializedLayout() {
     }
 
     /**
      * Formats a {@link org.apache.logging.log4j.core.LogEvent} in conformance with the log4j.dtd.
      */
     public byte[] format(final LogEvent event) {
-
-        // Reset working buffer. If the buffer is too large, then we need a new
-        // one in order to avoid the penalty of creating a large array.
-        if (buf.capacity() > UPPER_LIMIT) {
-            buf = new StringBuilder(DEFAULT_SIZE);
-        } else {
-            buf.setLength(0);
-        }
-
-        // We yield to the \r\n heresy.
-
-        buf.append("<log4j:event logger=\"");
-        String name = event.getLoggerName();
-        if (name.length() == 0) {
-            name = "root";
-        }
-        buf.append(Transform.escapeTags(name));
-        buf.append("\" timestamp=\"");
-        buf.append(event.getMillis());
-        buf.append("\" level=\"");
-        buf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
-        buf.append("\" thread=\"");
-        buf.append(Transform.escapeTags(event.getThreadName()));
-        buf.append("\">\r\n");
-
-        buf.append("<log4j:message><![CDATA[");
-        // Append the rendered message. Also make sure to escape any
-        // existing CDATA sections.
-        Transform.appendEscapingCDATA(buf, event.getMessage().getFormattedMessage());
-        buf.append("]]></log4j:message>\r\n");
-
-        if (event.getContextStack().size() > 0) {
-            buf.append("<log4j:NDC><![CDATA[");
-            Transform.appendEscapingCDATA(buf, event.getContextStack().toString());
-            buf.append("]]></log4j:NDC>\r\n");
-        }
-
-        Throwable throwable = event.getThrown();
-        if (throwable != null) {
-            List<String> s = getThrowableString(throwable);
-            buf.append("<log4j:throwable><![CDATA[");
-            for (String str : s) {
-                Transform.appendEscapingCDATA(buf, str);
-                buf.append("\r\n");
-            }
-            buf.append("]]></log4j:throwable>\r\n");
-        }
-
-        if (locationInfo) {
-            StackTraceElement element = event.getSource();
-            buf.append("<log4j:locationInfo class=\"");
-            buf.append(Transform.escapeTags(element.getClassName()));
-            buf.append("\" method=\"");
-            buf.append(Transform.escapeTags(element.getMethodName()));
-            buf.append("\" file=\"");
-            buf.append(Transform.escapeTags(element.getFileName()));
-            buf.append("\" line=\"");
-            buf.append(element.getLineNumber());
-            buf.append("\"/>\r\n");
-        }
-
-        if (properties && event.getContextMap().size() > 0) {
-            buf.append("<log4j:properties>\r\n");
-            for (Map.Entry<String, Object> entry : event.getContextMap().entrySet())
{
-                buf.append("<log4j:data name=\"");
-                buf.append(Transform.escapeTags(entry.getKey()));
-                buf.append("\" value=\"");
-                buf.append(Transform.escapeTags(String.valueOf(entry.getValue())));
-                buf.append("\"/>\r\n");
-            }
-            buf.append("</log4j:properties>\r\n");
-        }
-
-        buf.append("</log4j:event>\r\n\r\n");
-
-        return buf.toString().getBytes(charset);
-    }
-
-    /**
-     * Returns appropriate XML headers.
-     */
-    @Override
-    public byte[] getHeader() {
-        if (!complete) {
-            return null;
-        }
-        StringBuilder sbuf = new StringBuilder();
-        sbuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
-        sbuf.append("<log4j:eventSet xmlns:log4j=\"http://jakarta.apache.org/log4j/\">\r\n");
-        return sbuf.toString().getBytes(charset);
-    }
-
-
-    /**
-     * Returns appropriate XML headers.
-     */
-    @Override
-    public byte[] getFooter() {
-        if (!complete) {
-            return null;
-        }
-        StringBuilder sbuf = new StringBuilder();
-        sbuf.append("</log4j:eventSet>\r\n");
-        return sbuf.toString().getBytes(charset);
-    }
-
-    List<String> getThrowableString(Throwable throwable) {
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new PrintWriter(sw);
-        try {
-            throwable.printStackTrace(pw);
-        } catch(RuntimeException ex) {
-        }
-        pw.flush();
-        LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
-        ArrayList<String> lines = new ArrayList<String>();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
-          String line = reader.readLine();
-          while(line != null) {
-            lines.add(line);
-            line = reader.readLine();
-          }
-        } catch(IOException ex) {
-            if (ex instanceof InterruptedIOException) {
-                Thread.currentThread().interrupt();
-            }
-            lines.add(ex.toString());
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(event);
+        } catch (IOException ioe) {
+            logger.error("Serialization of Logging Event failed.", ioe);
         }
-        return lines;
+        return baos.toByteArray();
     }
 
     @PluginFactory
-    public static XMLLayout createLayout(@PluginAttr("locationInfo") String locationInfo,
-                                         @PluginAttr("properties") String properties,
-                                         @PluginAttr("complete") String complete,
-                                         @PluginAttr("charset") String charset) {
-        Charset c = Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset();
-        if (charset != null) {
-            if (Charset.isSupported(charset)) {
-                c = Charset.forName(charset);
-            } else {
-                logger.error("Charset " + charset + " is not supported for layout, using
" + c.displayName());
-            }
-        }
-        boolean info = locationInfo == null ? false : Boolean.valueOf(locationInfo);
-        boolean props = properties == null ? false : Boolean.valueOf(properties);
-        boolean comp = complete == null ? false : Boolean.valueOf(complete);
-        return new XMLLayout(info, props, comp, c);
+    public static SerializedLayout createLayout() {
+
+        return new SerializedLayout();
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java
Fri May 27 01:39:09 2011
@@ -71,14 +71,12 @@ import org.apache.logging.log4j.core.Log
 @Plugin(name="XMLLayout",type="Core",elementType="layout",printObject=true)
 public class XMLLayout extends LayoutBase {
 
-    private static final int DEFAULT_SIZE = 256;
-    private static final int UPPER_LIMIT = 2048;
-
-    private StringBuilder buf = new StringBuilder(DEFAULT_SIZE);
     private final boolean locationInfo;
     private final boolean properties;
     private final boolean complete;
 
+    protected static final int DEFAULT_SIZE = 256;
+
     protected final Charset charset;
 
     public XMLLayout(boolean locationInfo, boolean properties, boolean complete, Charset
charset) {
@@ -92,14 +90,7 @@ public class XMLLayout extends LayoutBas
      * Formats a {@link org.apache.logging.log4j.core.LogEvent} in conformance with the log4j.dtd.
      */
     public byte[] format(final LogEvent event) {
-
-        // Reset working buffer. If the buffer is too large, then we need a new
-        // one in order to avoid the penalty of creating a large array.
-        if (buf.capacity() > UPPER_LIMIT) {
-            buf = new StringBuilder(DEFAULT_SIZE);
-        } else {
-            buf.setLength(0);
-        }
+        StringBuilder buf = new StringBuilder(DEFAULT_SIZE);
 
         // We yield to the \r\n heresy.
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/HTMLLayoutTest.java
Fri May 27 01:39:09 2011
@@ -70,7 +70,7 @@ public class HTMLLayoutTest {
 
         // set up appender
         HTMLLayout layout = HTMLLayout.createLayout("true", null, null, null);
-        ListAppender appender = new ListAppender("List", null, layout, true);
+        ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 
         // set appender on root and set level to debug

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/SerializedLayoutTest.java
(from r1127788, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/SerializedLayoutTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/SerializedLayoutTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java&r1=1127788&r2=1128132&rev=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/SerializedLayoutTest.java
Fri May 27 01:39:09 2011
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.BasicConfigurationFactory;
+import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
@@ -29,6 +30,9 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.util.List;
 
 import static org.junit.Assert.assertTrue;
@@ -36,7 +40,7 @@ import static org.junit.Assert.assertTru
 /**
  *
  */
-public class XMLLayoutTest {
+public class SerializedLayoutTest {
     LoggerContext ctx = (LoggerContext) LogManager.getContext();
     Logger root = ctx.getLogger("");
 
@@ -57,6 +61,13 @@ public class XMLLayoutTest {
     private static final String body =
         "<log4j:message><![CDATA[empty mdc]]></log4j:message>\r";
 
+    private static final String[] expected = {
+        "Logger=root Level=DEBUG Messagestarting mdc pattern test",
+        "Logger=root Level=DEBUG Messageempty mdc",
+        "Logger=root Level=DEBUG Messagefilled mdc",
+        "Logger=root Level=ERROR Messagefinished mdc pattern test"
+    };
+
 
     /**
      * Test case for MDC conversion pattern.
@@ -65,8 +76,8 @@ public class XMLLayoutTest {
     public void testLayout() throws Exception {
 
         // set up appender
-        XMLLayout layout = XMLLayout.createLayout("true", "true", "true", null);
-        ListAppender appender = new ListAppender("List", null, layout, true);
+        SerializedLayout layout = SerializedLayout.createLayout();
+        ListAppender appender = new ListAppender("List", null, layout, false, true);
         appender.start();
 
         // set appender on root and set level to debug
@@ -90,11 +101,16 @@ public class XMLLayoutTest {
 
         appender.stop();
 
-        List<String> list = appender.getMessages();
+        List<byte[]> data = appender.getData();
+        assertTrue(data.size() > 0);
+        int i = 0;
+        for (byte[] item : data) {
+            ByteArrayInputStream bais = new ByteArrayInputStream(item);
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            LogEvent event = (LogEvent) ois.readObject();
+            assertTrue("Incorrect event", event.toString().equals(expected[i]));
+            ++i;
+        }
 
-        assertTrue("Incorrect number of lines. Require at least 50 " + list.size(), list.size()
> 50);
-        assertTrue("Incorrect header", list.get(0).equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r"));
-        assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</log4j:eventSet>\r"));
-        assertTrue("Incorrect body. Expected " + body + " Actual: " + list.get(8), list.get(8).equals(body));
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java?rev=1128132&r1=1128131&r2=1128132&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/XMLLayoutTest.java
Fri May 27 01:39:09 2011
@@ -66,7 +66,7 @@ public class XMLLayoutTest {
 
         // set up appender
         XMLLayout layout = XMLLayout.createLayout("true", "true", "true", null);
-        ListAppender appender = new ListAppender("List", null, layout, true);
+        ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 
         // set appender on root and set level to debug



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message