Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-328

XMLLayout has several inconsistencies as compared to the log4j XMLLayout it emulates.

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      All

      Description

      XMLLayout has the following issues, relative to the log4j XMLLayout implementation:
      1. The stack trace does not include the exception class
      2. The stack trace does not walk the "caused by" chain

      The following quickie patch resolves these two issues, but may introduce others.

      public class XMLLayout extends LayoutBase
      {
      ... snip ...

      public String doLayout(ILoggingEvent event)
      {

      ... snip ...

      buf.append(" <log4j:message><![CDATA[");
      Transform.appendEscapingCDATA(buf, event.getFormattedMessage());
      buf.append("]]></log4j:message>\r\n");
      IThrowableProxy tp = event.getThrowableProxy();

      StackTraceElementProxy arr$[]; // I'm hopelessly addicted to keeping declarations out of tight loops
      StackTraceElementProxy step;
      StackTraceElementProxy stepArray[];
      int len$;

      if (tp != null)
      {
      stepArray = tp.getStackTraceElementProxyArray();
      buf.append(" <log4j:throwable><![CDATA[");

      while (tp != null) { // loop to walk the caused-by chain
      buf.append(tp.getClassName()); // put the exception's class name in the stacktrace, per log4j reference

      buf.append(" : ");
      buf.append(tp.getMessage());
      buf.append(" :\r\n");
      arr$ = stepArray;
      len$ = arr$.length;
      for (int i$ = 0; i$ < len$; i$++)

      { step = arr$[i$]; buf.append('\t'); buf.append(step.toString()); buf.append("\r\n"); }

      tp = tp.getCause(); // go to the next exception in the chain
      if (tp != null)

      { buf.append("Caused by: "); }

      }
      buf.append("]]></log4j:throwable>\r\n");
      }

      if(locationInfo)
      {
      StackTraceElement callerDataArray[] = event.getCallerData();
      if(callerDataArray != null && callerDataArray.length > 0)
      {
      ... snip ...

        Attachments

          Activity

            People

            • Assignee:
              logback-dev Logback dev list
              Reporter:
              swift99 David Johnson
            • Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: