class LogstashEventFormat implements LoggingEventFormat {

    public String toString(PaxLoggingEvent event) {
        JsonObjectBuilder object = Json.createObjectBuilder();
        try {
            object.add(MESSAGE, event.getMessage());
            object.add(SOURCE, event.getLoggerName());
            object.add(TIMESTAMP, TIMESTAMP_FORMAT.format(new Date(event.getTimeStamp())));

            JsonObjectBuilder fields = Json.createObjectBuilder();
            for (Object property : event.getProperties().entrySet()) {
                Map.Entry<String, Object> entry = (Map.Entry<String, Object>) property;
                fields.add(entry.getKey(), entry.getValue().toString());
            }

            object.add(FIELDS, fields);

            JsonArrayBuilder tags = Json.createArrayBuilder();
            tags.add(event.getLevel().toString());
            object.add(TAGS, tags);
        } catch (JsonException e) {
            // let's return a minimal, String-based message representation instead
            return "{ \"" + MESSAGE + "\" : " + event.getMessage() + "}";
        }
        return object.build().toString();
    }

}