String shortMessage = message;
if (message.length() > MAX_SHORT_MESSAGE_LENGTH) {
shortMessage = message.substring(0, MAX_SHORT_MESSAGE_LENGTH - 1);
}
final GelfMessage gelfMessage = new GelfMessage(shortMessage, message, logEvent.getLogTimestamp(),
logEvent.getSyslogLevel());
SimpleDateFormat dateFormat = new SimpleDateFormat(timestampPattern);
gelfMessage.addField(FIELD_TIME, dateFormat.format(new Date(logEvent.getLogTimestamp())));
gelfMessage.addField(FIELD_SEVERITY, logEvent.getLevelName());
gelfMessage.addField(FIELD_THREAD, logEvent.getThreadName());
gelfMessage.addField(FIELD_SOURCE_CLASS_NAME, logEvent.getSourceClassName());
String simpleClassName = logEvent.getSourceClassName();
int index = simpleClassName.lastIndexOf('.');
if (index != -1) {
simpleClassName = simpleClassName.substring(index + 1);
}
gelfMessage.addField(FIELD_SOURCE_SIMPLE_CLASS_NAME, simpleClassName);
gelfMessage.addField(FIELD_SOURCE_METHOD_NAME, logEvent.getSourceMethodName());
if (extractStackTrace) {
addStackTrace(logEvent, gelfMessage);
}
if (logEvent.getParameters() != null) {
for (int i = 0; i < logEvent.getParameters().length; i++) {
Object param = logEvent.getParameters()[i];
gelfMessage.addField(FIELD_MESSAGE_PARAM + i, "" + param);
}
}
gelfMessage.addField(FIELD_SERVER, getOriginHost());
gelfMessage.setHost(getOriginHost());
if (null != facility) {
gelfMessage.setFacility(facility);
}
for (Map.Entry<String, String> entry : fields.entrySet()) {
gelfMessage.addField(entry.getKey(), entry.getValue());
}
gelfMessage.setMaximumMessageSize(maximumMessageSize);
return gelfMessage;
}