You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2003/06/24 04:45:45 UTC

cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/xml XMLLayout.java

psmith      2003/06/23 19:45:45

  Modified:    src/java/org/apache/log4j/xml XMLLayout.java
  Log:
  Sandbox version of XMLLayout now conforms to the new Layout contract.
  
  Revision  Changes    Path
  1.3       +43 -51    jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java
  
  Index: XMLLayout.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLLayout.java	29 Apr 2003 16:21:30 -0000	1.2
  +++ XMLLayout.java	24 Jun 2003 02:45:45 -0000	1.3
  @@ -51,6 +51,8 @@
   // Contributors:   Mathias Bogaert
   package org.apache.log4j.xml;
   
  +import java.io.IOException;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.Set;
   
  @@ -94,9 +96,6 @@
    * @since 0.9.0
    * */
   public class XMLLayout extends Layout {
  -  private final int DEFAULT_SIZE = 256;
  -  private final int UPPER_LIMIT = 2048;
  -  private StringBuffer buf = new StringBuffer(DEFAULT_SIZE);
     private boolean locationInfo = false;
   
     /**
  @@ -128,108 +127,101 @@
     /**
      * Formats a {@link LoggingEvent} in conformance with the log4j.dtd.
      * */
  -  public String format(LoggingEvent 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 StringBuffer(DEFAULT_SIZE);
  -    } else {
  -      buf.setLength(0);
  -    }
  +  public void format(Writer output, LoggingEvent event)
  +   throws IOException {
   
       // We yield to the \r\n heresy.
  -    buf.append("<log4j:event logger=\"");
  -    buf.append(event.getLoggerName());
  -    buf.append("\" level=\"");
  -    buf.append(event.getLevel());
  -    buf.append("\" thread=\"");
  -    buf.append(event.getThreadName());
  -    buf.append("\" timestamp=\"");
  -    buf.append(event.timeStamp);
  -    buf.append("\">\r\n");
  +    output.write("<log4j:event logger=\"");
  +    output.write(event.getLoggerName());
  +    output.write("\" level=\"");
  +    output.write(String.valueOf(event.getLevel()));
  +    output.write("\" thread=\"");
  +    output.write(event.getThreadName());
  +    output.write("\" timestamp=\"");
  +    output.write(String.valueOf(event.timeStamp));
  +    output.write("\">\r\n");
   
  -    buf.append("<log4j:message><![CDATA[");
  +    output.write("<log4j:message><![CDATA[");
   
       // Append the rendered message. Also make sure to escape any
       // existing CDATA sections.
  -    Transform.appendEscapingCDATA(buf, event.getRenderedMessage());
  -    buf.append("]]></log4j:message>\r\n");
  +    Transform.appendEscapingCDATA(output, event.getRenderedMessage());
  +    output.write("]]></log4j:message>\r\n");
   
       String ndc = event.getNDC();
   
       if (ndc != null) {
  -      buf.append("<log4j:NDC><![CDATA[");
  -      buf.append(ndc);
  -      buf.append("]]></log4j:NDC>\r\n");
  +      output.write("<log4j:NDC><![CDATA[");
  +      output.write(ndc);
  +      output.write("]]></log4j:NDC>\r\n");
       }
   
       Set mdcSet = event.getMDCKeySet();
   
       if ((mdcSet != null) && (mdcSet.size() > 0)) {
  -      buf.append("<log4j:MDC>");
  +      output.write("<log4j:MDC>");
   
         Iterator iter = mdcSet.iterator();
   
         while (iter.hasNext()) {
           String propName = (String) iter.next();
  -        buf.append("<log4j:data name=\"" + propName);
  +        output.write("<log4j:data name=\"" + propName);
   
           String propValue = (String) event.getMDC(propName);
  -        buf.append("\" value=\"" + propValue);
  -        buf.append("\"/>\r\n");
  +        output.write("\" value=\"" + propValue);
  +        output.write("\"/>\r\n");
         }
   
  -      buf.append("</log4j:MDC>\r\n");
  +      output.write("</log4j:MDC>\r\n");
       }
   
       String[] s = event.getThrowableStrRep();
   
       if (s != null) {
  -      buf.append("<log4j:throwable><![CDATA[");
  +      output.write("<log4j:throwable><![CDATA[");
   
         for (int i = 0; i < s.length; i++) {
  -        buf.append(s[i]);
  -        buf.append("\r\n");
  +        output.write(s[i]);
  +        output.write("\r\n");
         }
   
  -      buf.append("]]></log4j:throwable>\r\n");
  +      output.write("]]></log4j:throwable>\r\n");
       }
   
       if (locationInfo) {
         LocationInfo locationInfo = event.getLocationInformation();
  -      buf.append("<log4j:locationInfo class=\"");
  -      buf.append(locationInfo.getClassName());
  -      buf.append("\" method=\"");
  -      buf.append(Transform.escapeTags(locationInfo.getMethodName()));
  -      buf.append("\" file=\"");
  -      buf.append(locationInfo.getFileName());
  -      buf.append("\" line=\"");
  -      buf.append(locationInfo.getLineNumber());
  -      buf.append("\"/>\r\n");
  +      output.write("<log4j:locationInfo class=\"");
  +      output.write(locationInfo.getClassName());
  +      output.write("\" method=\"");
  +      Transform.escapeTags(locationInfo.getMethodName(), output);
  +      output.write("\" file=\"");
  +      output.write(locationInfo.getFileName());
  +      output.write("\" line=\"");
  +      output.write(locationInfo.getLineNumber());
  +      output.write("\"/>\r\n");
       }
   
       Set propertySet = event.getPropertyKeySet();
   
       if ((propertySet != null) && (propertySet.size() > 0)) {
  -      buf.append("<log4j:properties>");
  +      output.write("<log4j:properties>");
   
         Iterator propIter = propertySet.iterator();
   
         while (propIter.hasNext()) {
           String propName = (String) propIter.next();
  -        buf.append("<log4j:data name=\"" + propName);
  +        output.write("<log4j:data name=\"" + propName);
   
           String propValue = (String) event.getProperty(propName);
  -        buf.append("\" value=\"" + propValue);
  -        buf.append("\"/>\r\n");
  +        output.write("\" value=\"" + propValue);
  +        output.write("\"/>\r\n");
         }
   
  -      buf.append("</log4j:properties>\r\n");
  +      output.write("</log4j:properties>\r\n");
       }
   
  -    buf.append("</log4j:event>\r\n\r\n");
  +    output.write("</log4j:event>\r\n\r\n");
   
  -    return buf.toString();
     }
   
     /**
  
  
  

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


Re: cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/xml XMLLayout.java

Posted by Ceki Gülcü <ce...@qos.ch>.

Sorry my previous message went off too quickly.

Hi Mark, Paul, Scott,

This commit was probably not necessary at all. What is the difference
between this XMLLayout and the one in log4j proper? Can we remove this
duplicate file?

Having duplicates lying around makes it quite difficult to maintain
the code. Now that both Scott and you have access to the log4j CVS
repository and not just the sandbox, I ask you please stop maintaining
duplicates in log4j and log4j-sandbox. Given that your enhancements to
chainsaw remain unchallenged, please also migrate chainsaw as well as
the new plugin, receiver code.

Is that OK with everyone? Mark?


At 02:45 AM 6/24/2003 +0000, you wrote:
>psmith      2003/06/23 19:45:45
>
>   Modified:    src/java/org/apache/log4j/xml XMLLayout.java
>   Log:
>   Sandbox version of XMLLayout now conforms to the new Layout contract.
>
>   Revision  Changes    Path
>   1.3       +43 
> -51    jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java
>
>   Index: XMLLayout.java
>   ===================================================================
>   RCS file: 
> /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java,v
>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- XMLLayout.java    29 Apr 2003 16:21:30 -0000      1.2
>   +++ XMLLayout.java    24 Jun 2003 02:45:45 -0000      1.3
>   @@ -51,6 +51,8 @@
>    // Contributors:   Mathias Bogaert
>    package org.apache.log4j.xml;
>
>   +import java.io.IOException;
>   +import java.io.Writer;
>    import java.util.Iterator;
>    import java.util.Set;
>
>   @@ -94,9 +96,6 @@
>     * @since 0.9.0
>     * */
>    public class XMLLayout extends Layout {
>   -  private final int DEFAULT_SIZE = 256;
>   -  private final int UPPER_LIMIT = 2048;
>   -  private StringBuffer buf = new StringBuffer(DEFAULT_SIZE);
>      private boolean locationInfo = false;
>
>      /**
>   @@ -128,108 +127,101 @@
>      /**
>       * Formats a {@link LoggingEvent} in conformance with the log4j.dtd.
>       * */

--
Ceki  For log4j documentation consider "The complete log4j manual"
       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp 


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


Re: cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/xml XMLLayout.java

Posted by Ceki Gülcü <ce...@qos.ch>.
Hi Paul,

This commit was probably not necessary at all. Having duplicates lying 
around makes it very difficult to maintain the code. Now that both Scott 
and you have access to the log4j CVS

At 02:45 AM 6/24/2003 +0000, you wrote:
>psmith      2003/06/23 19:45:45
>
>   Modified:    src/java/org/apache/log4j/xml XMLLayout.java
>   Log:
>   Sandbox version of XMLLayout now conforms to the new Layout contract.
>
>   Revision  Changes    Path
>   1.3       +43 
> -51    jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java
>
>   Index: XMLLayout.java
>   ===================================================================
>   RCS file: 
> /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLLayout.java,v
>   retrieving revision 1.2
>   retrieving revision 1.3
>   diff -u -r1.2 -r1.3
>   --- XMLLayout.java    29 Apr 2003 16:21:30 -0000      1.2
>   +++ XMLLayout.java    24 Jun 2003 02:45:45 -0000      1.3
>   @@ -51,6 +51,8 @@
>    // Contributors:   Mathias Bogaert
>    package org.apache.log4j.xml;
>
>   +import java.io.IOException;
>   +import java.io.Writer;
>    import java.util.Iterator;
>    import java.util.Set;
>
>   @@ -94,9 +96,6 @@
>     * @since 0.9.0
>     * */
>    public class XMLLayout extends Layout {
>   -  private final int DEFAULT_SIZE = 256;
>   -  private final int UPPER_LIMIT = 2048;
>   -  private StringBuffer buf = new StringBuffer(DEFAULT_SIZE);
>      private boolean locationInfo = false;
>
>      /**
>   @@ -128,108 +127,101 @@
>      /**
>       * Formats a {@link LoggingEvent} in conformance with the log4j.dtd.
>       * */
>   -  public String format(LoggingEvent 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 StringBuffer(DEFAULT_SIZE);
>   -    } else {
>   -      buf.setLength(0);
>   -    }
>   +  public void format(Writer output, LoggingEvent event)
>   +   throws IOException {
>
>        // We yield to the \r\n heresy.
>   -    buf.append("<log4j:event logger=\"");
>   -    buf.append(event.getLoggerName());
>   -    buf.append("\" level=\"");
>   -    buf.append(event.getLevel());
>   -    buf.append("\" thread=\"");
>   -    buf.append(event.getThreadName());
>   -    buf.append("\" timestamp=\"");
>   -    buf.append(event.timeStamp);
>   -    buf.append("\">\r\n");
>   +    output.write("<log4j:event logger=\"");
>   +    output.write(event.getLoggerName());
>   +    output.write("\" level=\"");
>   +    output.write(String.valueOf(event.getLevel()));
>   +    output.write("\" thread=\"");
>   +    output.write(event.getThreadName());
>   +    output.write("\" timestamp=\"");
>   +    output.write(String.valueOf(event.timeStamp));
>   +    output.write("\">\r\n");
>
>   -    buf.append("<log4j:message><![CDATA[");
>   +    output.write("<log4j:message><![CDATA[");
>
>        // Append the rendered message. Also make sure to escape any
>        // existing CDATA sections.
>   -    Transform.appendEscapingCDATA(buf, event.getRenderedMessage());
>   -    buf.append("]]></log4j:message>\r\n");
>   +    Transform.appendEscapingCDATA(output, event.getRenderedMessage());
>   +    output.write("]]></log4j:message>\r\n");
>
>        String ndc = event.getNDC();
>
>        if (ndc != null) {
>   -      buf.append("<log4j:NDC><![CDATA[");
>   -      buf.append(ndc);
>   -      buf.append("]]></log4j:NDC>\r\n");
>   +      output.write("<log4j:NDC><![CDATA[");
>   +      output.write(ndc);
>   +      output.write("]]></log4j:NDC>\r\n");
>        }
>
>        Set mdcSet = event.getMDCKeySet();
>
>        if ((mdcSet != null) && (mdcSet.size() > 0)) {
>   -      buf.append("<log4j:MDC>");
>   +      output.write("<log4j:MDC>");
>
>          Iterator iter = mdcSet.iterator();
>
>          while (iter.hasNext()) {
>            String propName = (String) iter.next();
>   -        buf.append("<log4j:data name=\"" + propName);
>   +        output.write("<log4j:data name=\"" + propName);
>
>            String propValue = (String) event.getMDC(propName);
>   -        buf.append("\" value=\"" + propValue);
>   -        buf.append("\"/>\r\n");
>   +        output.write("\" value=\"" + propValue);
>   +        output.write("\"/>\r\n");
>          }
>
>   -      buf.append("</log4j:MDC>\r\n");
>   +      output.write("</log4j:MDC>\r\n");
>        }
>
>        String[] s = event.getThrowableStrRep();
>
>        if (s != null) {
>   -      buf.append("<log4j:throwable><![CDATA[");
>   +      output.write("<log4j:throwable><![CDATA[");
>
>          for (int i = 0; i < s.length; i++) {
>   -        buf.append(s[i]);
>   -        buf.append("\r\n");
>   +        output.write(s[i]);
>   +        output.write("\r\n");
>          }
>
>   -      buf.append("]]></log4j:throwable>\r\n");
>   +      output.write("]]></log4j:throwable>\r\n");
>        }
>
>        if (locationInfo) {
>          LocationInfo locationInfo = event.getLocationInformation();
>   -      buf.append("<log4j:locationInfo class=\"");
>   -      buf.append(locationInfo.getClassName());
>   -      buf.append("\" method=\"");
>   -      buf.append(Transform.escapeTags(locationInfo.getMethodName()));
>   -      buf.append("\" file=\"");
>   -      buf.append(locationInfo.getFileName());
>   -      buf.append("\" line=\"");
>   -      buf.append(locationInfo.getLineNumber());
>   -      buf.append("\"/>\r\n");
>   +      output.write("<log4j:locationInfo class=\"");
>   +      output.write(locationInfo.getClassName());
>   +      output.write("\" method=\"");
>   +      Transform.escapeTags(locationInfo.getMethodName(), output);
>   +      output.write("\" file=\"");
>   +      output.write(locationInfo.getFileName());
>   +      output.write("\" line=\"");
>   +      output.write(locationInfo.getLineNumber());
>   +      output.write("\"/>\r\n");
>        }
>
>        Set propertySet = event.getPropertyKeySet();
>
>        if ((propertySet != null) && (propertySet.size() > 0)) {
>   -      buf.append("<log4j:properties>");
>   +      output.write("<log4j:properties>");
>
>          Iterator propIter = propertySet.iterator();
>
>          while (propIter.hasNext()) {
>            String propName = (String) propIter.next();
>   -        buf.append("<log4j:data name=\"" + propName);
>   +        output.write("<log4j:data name=\"" + propName);
>
>            String propValue = (String) event.getProperty(propName);
>   -        buf.append("\" value=\"" + propValue);
>   -        buf.append("\"/>\r\n");
>   +        output.write("\" value=\"" + propValue);
>   +        output.write("\"/>\r\n");
>          }
>
>   -      buf.append("</log4j:properties>\r\n");
>   +      output.write("</log4j:properties>\r\n");
>        }
>
>   -    buf.append("</log4j:event>\r\n\r\n");
>   +    output.write("</log4j:event>\r\n\r\n");
>
>   -    return buf.toString();
>      }
>
>      /**
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki  For log4j documentation consider "The complete log4j manual"
       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp 


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