Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
214 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.splunk.logging; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
import org.json.simple.JSONObject; | ||
|
||
public interface EventBodySerializer { | ||
|
||
String serializeEventBody( | ||
HttpEventCollectorEventInfo eventInfo, | ||
Object formattedMessage | ||
); | ||
|
||
class Default implements EventBodySerializer { | ||
|
||
@Override | ||
public String serializeEventBody( | ||
final HttpEventCollectorEventInfo eventInfo, | ||
final Object formattedMessage | ||
) { | ||
final JSONObject body = new JSONObject(); | ||
HttpEventCollectorSender.putIfPresent(body, "severity", eventInfo.getSeverity()); | ||
HttpEventCollectorSender.putIfPresent(body, "message", formattedMessage); | ||
HttpEventCollectorSender.putIfPresent(body, "logger", eventInfo.getLoggerName()); | ||
HttpEventCollectorSender.putIfPresent(body, "thread", eventInfo.getThreadName()); | ||
// add an exception record if and only if there is one | ||
// in practice, the message also has the exception information attached | ||
if (eventInfo.getExceptionMessage() != null) { | ||
HttpEventCollectorSender.putIfPresent(body, "exception", eventInfo.getExceptionMessage()); | ||
} | ||
|
||
// add properties if and only if there are any | ||
final Map<String, String> props = eventInfo.getProperties(); | ||
if (props != null && !props.isEmpty()) { | ||
body.put("properties", props); | ||
} | ||
// add marker if and only if there is one | ||
final Serializable marker = eventInfo.getMarker(); | ||
if (marker != null) { | ||
HttpEventCollectorSender.putIfPresent(body, "marker", marker.toString()); | ||
} | ||
|
||
return body.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.