Search in sources :

Example 1 with GelfMessageBuilder

use of org.graylog2.gelfclient.GelfMessageBuilder in project graylog2-server by Graylog2.

the class GelfOutput method toGELFMessage.

protected GelfMessage toGELFMessage(final Message message) {
    final DateTime timestamp;
    final Object fieldTimeStamp = message.getField(Message.FIELD_TIMESTAMP);
    if (fieldTimeStamp instanceof DateTime) {
        timestamp = (DateTime) fieldTimeStamp;
    } else {
        timestamp = Tools.nowUTC();
    }
    final GelfMessageLevel messageLevel = extractLevel(message.getField(Message.FIELD_LEVEL));
    final String fullMessage = (String) message.getField(Message.FIELD_FULL_MESSAGE);
    final String facility = (String) message.getField("facility");
    final String forwarder = GelfOutput.class.getCanonicalName();
    final GelfMessageBuilder builder = new GelfMessageBuilder(message.getMessage(), message.getSource()).timestamp(timestamp.getMillis() / 1000.0d).additionalField("_forwarder", forwarder).additionalFields(message.getFields());
    if (messageLevel != null) {
        builder.level(messageLevel);
    }
    if (fullMessage != null) {
        builder.fullMessage(fullMessage);
    }
    if (facility != null) {
        builder.additionalField("_facility", facility);
    }
    return builder.build();
}
Also used : GelfMessageLevel(org.graylog2.gelfclient.GelfMessageLevel) GelfMessageBuilder(org.graylog2.gelfclient.GelfMessageBuilder) DateTime(org.joda.time.DateTime)

Aggregations

GelfMessageBuilder (org.graylog2.gelfclient.GelfMessageBuilder)1 GelfMessageLevel (org.graylog2.gelfclient.GelfMessageLevel)1 DateTime (org.joda.time.DateTime)1