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());
for (MessageField field : fields) {
Values values = getValues(logEvent, field);
if (values == null || !values.hasValues()) {
continue;
}
for (String entryName : values.getEntryNames())
{
String value = values.getValue(entryName);
if(value == null)
{
continue;
}
gelfMessage.addField(entryName, value);
}
}
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.setHost(getOriginHost());
if (null != facility) {
gelfMessage.setFacility(facility);
}
gelfMessage.setMaximumMessageSize(maximumMessageSize);
return gelfMessage;
}