Class EcsJsonUtils
java.lang.Object
org.elasticsearch.cli.terminal.internal.EcsJsonUtils
Minimal, zero-dependency ECS JSON formatter for CLI and launcher output.
Formats messages as single-line JSON conforming to a subset of the Elastic Common Schema. This is intentionally self-contained (no log4j, no ecs-logging-core) so it can be used in the GraalVM native-image launcher as well as the CLI preparer process.
The looksLikeJson(java.lang.CharSequence) method can be used to check whether a line already
looks like JSON (starts with a left curly brace) and should be passed through unchanged.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatJson(String level, String logger, CharSequence message) Formats a plain message as a single-line ECS JSON string.static StringformatJson(String level, String logger, CharSequence message, Throwable throwable) Formats a message with a throwable as a single-line ECS JSON string (no trailing newline).static booleanlooksLikeJson(CharSequence line) Returnstrueif the line appears to already be a JSON object.static boolean
-
Method Details
-
useJsonOutput
public static boolean useJsonOutput() -
formatJson
Formats a plain message as a single-line ECS JSON string. -
formatJson
public static String formatJson(String level, String logger, CharSequence message, Throwable throwable) Formats a message with a throwable as a single-line ECS JSON string (no trailing newline). The full stacktrace goes intoerror.stack_traceand the exception class intoerror.type. -
looksLikeJson
Returnstrueif the line appears to already be a JSON object.
-