io.quarkiverse.logging.splunk.SplunkFlatEventSerializer Maven / Gradle / Ivy
The newest version!
package io.quarkiverse.logging.splunk;
import java.util.HashMap;
import java.util.Map;
import com.splunk.logging.EventBodySerializer;
import com.splunk.logging.EventHeaderSerializer;
import com.splunk.logging.HttpEventCollectorEventInfo;
class SplunkFlatEventSerializer implements EventHeaderSerializer, EventBodySerializer {
private final String metadataSeverityFieldName;
SplunkFlatEventSerializer(String metadataSeverityFieldName) {
this.metadataSeverityFieldName = metadataSeverityFieldName;
}
;
/**
* Serialization of the root JSON object of the event
*/
@Override
public Map serializeEventHeader(HttpEventCollectorEventInfo eventInfo, Map metadata) {
Map fields = (Map) metadata.computeIfAbsent("fields", k -> new HashMap<>());
fields.put(this.metadataSeverityFieldName, eventInfo.getSeverity());
if (eventInfo.getLoggerName() != null) {
fields.put("logger", eventInfo.getLoggerName());
}
if (eventInfo.getThreadName() != null) {
fields.put("thread", eventInfo.getThreadName());
}
if (eventInfo.getExceptionMessage() != null) {
fields.put("exception", eventInfo.getExceptionMessage());
}
fields.putAll(eventInfo.getProperties());
return metadata;
}
/**
* Serialization of the "event" field
*/
@Override
public String serializeEventBody(HttpEventCollectorEventInfo eventInfo, Object formattedMessage) {
return eventInfo.getMessage();
}
/**
* We have to override this, because, by default, splunk-library-java does not send timestamp to Splunk.
* Refer to this pull-request on github
*/
@Override
public double getEventTime(HttpEventCollectorEventInfo eventInfo) {
return eventInfo.getTime();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy