java.lang.Object
org.elasticsearch.cli.terminal.internal.EcsJsonUtils

public final class EcsJsonUtils extends Object
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 Details

    • useJsonOutput

      public static boolean useJsonOutput()
    • formatJson

      public static String formatJson(String level, String logger, CharSequence message)
      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 into error.stack_trace and the exception class into error.type.
    • looksLikeJson

      public static boolean looksLikeJson(CharSequence line)
      Returns true if the line appears to already be a JSON object.