Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
None
-
None
-
None
-
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$++)
tp = tp.getCause(); // go to the next exception in the chain
if (tp != null)
}
buf.append("]]></log4j:throwable>\r\n");
}
if(locationInfo)
{
StackTraceElement callerDataArray[] = event.getCallerData();
if(callerDataArray != null && callerDataArray.length > 0)
{
... snip ...