in log4j-1.2-api/src/main/java/org/apache/log4j/layout/Log4j1XmlLayout.java [89:164]
private void formatTo(final LogEvent event, final StringBuilder buf) {
buf.append("<log4j:event logger=\"");
buf.append(Transform.escapeHtmlTags(event.getLoggerName()));
buf.append("\" timestamp=\"");
buf.append(event.getTimeMillis());
buf.append("\" level=\"");
buf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel())));
buf.append("\" thread=\"");
buf.append(Transform.escapeHtmlTags(event.getThreadName()));
buf.append("\">");
buf.append(EOL);
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>");
buf.append(EOL);
final List<String> ndc = event.getContextStack().asList();
if (!ndc.isEmpty()) {
buf.append("<log4j:NDC><![CDATA[");
Transform.appendEscapingCData(buf, Strings.join(ndc, ' '));
buf.append("]]></log4j:NDC>");
buf.append(EOL);
}
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final Throwable thrown = event.getThrown();
if (thrown != null) {
buf.append("<log4j:throwable><![CDATA[");
final StringWriter w = new StringWriter();
thrown.printStackTrace(new PrintWriter(w));
Transform.appendEscapingCData(buf, w.toString());
buf.append("]]></log4j:throwable>");
buf.append(EOL);
}
if (locationInfo) {
final StackTraceElement source = event.getSource();
if (source != null) {
buf.append("<log4j:locationInfo class=\"");
buf.append(Transform.escapeHtmlTags(source.getClassName()));
buf.append("\" method=\"");
buf.append(Transform.escapeHtmlTags(source.getMethodName()));
buf.append("\" file=\"");
buf.append(Transform.escapeHtmlTags(source.getFileName()));
buf.append("\" line=\"");
buf.append(source.getLineNumber());
buf.append("\"/>");
buf.append(EOL);
}
}
if (properties) {
final ReadOnlyStringMap contextMap = event.getContextData();
if (!contextMap.isEmpty()) {
buf.append("<log4j:properties>\r\n");
contextMap.forEach((key, val) -> {
if (val != null) {
buf.append("<log4j:data name=\"");
buf.append(Transform.escapeHtmlTags(key));
buf.append("\" value=\"");
buf.append(Transform.escapeHtmlTags(Objects.toString(val, null)));
buf.append("\"/>");
buf.append(EOL);
}
});
buf.append("</log4j:properties>");
buf.append(EOL);
}
}
buf.append("</log4j:event>");
buf.append(EOL);
buf.append(EOL);
}