import org.slf4j.MDC; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public String format(final LogRecord record) {
// 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);
}
buf.append("
buf.append(Transform.escapeTags(record.getLoggerName()));
buf.append("\" timestamp=\"");
buf.append(record.getMillis());
buf.append("\" level=\"");
buf.append(Transform.escapeTags(record.getLevel().getName()));
buf.append("\" thread=\"");
buf.append(String.valueOf(record.getThreadID()));
buf.append("\">\r\n");
buf.append("
// Append the rendered message. Also make sure to escape any
// existing CDATA sections.
Transform.appendEscapingCDATA(buf, record.getMessage());
buf.append("]]>
\r\n");if (record.getThrown() != null) {
String[] s = Transform.getThrowableStrRep(record.getThrown());
if (s != null) {
buf.append("
for (String value : s) {
Transform.appendEscapingCDATA(buf, value);
buf.append("\r\n");
}
buf.append("]]>
\r\n");}
}
if (locationInfo) {
buf.append("
buf.append(Transform.escapeTags(record.getSourceClassName()));
buf.append("\" method=\"");
buf.append(Transform.escapeTags(record.getSourceMethodName()));
buf.append("\" file=\"?\" line=\"?\"/>\r\n");
}
if (properties) {
Map contextMap = MDC.getCopyOfContextMap();
if (contextMap != null) {
Set keySet = contextMap.keySet();
if ((keySet != null) && (keySet.size() > 0)) {
buf.append("\r\n");
Object[] keys = keySet.toArray();
Arrays.sort(keys);
for (Object key1 : keys) {
String key = (key1 == null ? "" : key1.toString());
Object val = contextMap.get(key);
if (val != null) {
buf.append("
buf.append(Transform.escapeTags(key));
buf.append("\" value=\"");
buf.append(Transform.escapeTags(String.valueOf(val)));
buf.append("\"/>\r\n");
}
}
buf.append("\r\n");
}
}
}
buf.append("
\r\n\r\n");return buf.toString();
}