*
* @param event The LogEvent.
* @return The RFC 5424 String representation of the LogEvent.
*/
public String toSerializable(final LogEvent event) {
final Message msg = event.getMessage();
final boolean isStructured = msg instanceof StructuredDataMessage;
final StringBuilder buf = new StringBuilder();
buf.append("<");
buf.append(Priority.getPriority(facility, event.getLevel()));
buf.append(">1 ");
buf.append(computeTimeStampString(event.getMillis()));
buf.append(' ');
buf.append(localHostName);
buf.append(' ');
if (appName != null) {
buf.append(appName);
} else if (configName != null) {
buf.append(configName);
} else {
buf.append("-");
}
buf.append(" ");
buf.append(getProcId());
buf.append(" ");
final String type = isStructured ? ((StructuredDataMessage) msg).getType() : null;
if (type != null) {
buf.append(type);
} else if (messageId != null) {
buf.append(messageId);
} else {
buf.append("-");
}
buf.append(" ");
if (isStructured || includeMDC) {
StructuredDataId id = null;
String text;
if (isStructured) {
final StructuredDataMessage data = (StructuredDataMessage) msg;
final Map<String, String> map = data.getData();
id = data.getId();
formatStructuredElement(id, eventPrefix, map, buf, noopChecker);
text = data.getFormat();
} else {
text = msg.getFormattedMessage();
}
if (includeMDC) {
Map<String, String> map = event.getContextMap();
if (mdcRequired != null) {
checkRequired(map);
}
final int ein = id == null || id.getEnterpriseNumber() < 0 ?
enterpriseNumber : id.getEnterpriseNumber();
final StructuredDataId mdcSDID = new StructuredDataId(mdcId, ein, null, null);
formatStructuredElement(mdcSDID, mdcPrefix, map, buf, checker);
}
if (text != null && text.length() > 0) {
buf.append(" ").append(escapeNewlines(text, escapeNewLine));
}
} else {
buf.append("- ");
buf.append(escapeNewlines(msg.getFormattedMessage(), escapeNewLine));
}
if (formatters != null && event.getThrown() != null) {
final StringBuilder exception = new StringBuilder("\n");
for (final PatternFormatter formatter : formatters) {
formatter.format(event, exception);