Skip to content

Commit

Permalink
Add java docs
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <[email protected]>
  • Loading branch information
noCharger committed Mar 1, 2024
1 parent 5cf4ac2 commit 0534acd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import java.util.HashMap;
import java.util.Map;

/**
* CustomJsonLayout is a plugin for formatting log events as JSON strings.
*
* <p>The layout is designed to be used with OpenSearch Flint logging. It extracts environment-specific information,
* such as the cluster name, from the environment variable "FLINT_CLUSTER_NAME" and splits it into domain name and client ID.</p>
*
*/
@Plugin(name = "CustomJsonLayout", category = "Core", elementType = Layout.ELEMENT_TYPE, printObject = true)
public class CustomJsonLayout extends AbstractStringLayout {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
Expand All @@ -41,11 +48,24 @@ protected CustomJsonLayout(Charset charset) {
super(charset);
}

/**
* Plugin factory method to create an instance of CustomJsonLayout.
*
* @param charset The charset for encoding the log event. If not specified, defaults to UTF-8.
* @return A new instance of CustomJsonLayout with the specified charset.
*/
@PluginFactory
public static CustomJsonLayout createLayout(@PluginAttribute(value = "charset", defaultString = "UTF-8") Charset charset) {
return new CustomJsonLayout(charset);
}

/**
* Converts the log event to a JSON string.
* If the log event's message does not follow the expected format, it returns the formatted message directly.
*
* @param event the log event to format.
* @return A string representation of the log event in JSON format.
*/
@Override
public String toSerializable(LogEvent event) {
if (!(event.getMessage() instanceof OperationMessage)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @param <T> result type (supposed to be HttpResponse for OS client)
*/
public class HttpStatusCodeResultPredicate<T> implements CheckedPredicate<T> {

private static final Logger LOG = Logger.getLogger(HttpStatusCodeResultPredicate.class.getName());

/**
Expand Down

0 comments on commit 0534acd

Please sign in to comment.