[logback-dev] [JIRA] Created: (LBCLASSIC-315) XMLLayout has several inconsistencies as compared to the log4j XMLLayout it emulates.

David Johnson (JIRA) noreply-jira at qos.ch
Fri Dec 30 06:19:26 CET 2011


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

                 Key: LBCLASSIC-315
                 URL: http://jira.qos.ch/browse/LBCLASSIC-315
             Project: logback-classic
          Issue Type: Bug
         Environment: All
            Reporter: David Johnson
            Assignee: Logback dev list


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 ...

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list