Class KeyValueParameter

java.lang.Object
eu.mulk.quarkus.googlecloud.jsonlogging.KeyValueParameter
All Implemented Interfaces:
StructuredParameter

public final class KeyValueParameter extends Object implements StructuredParameter
A simple single key–value pair forming a StructuredParameter.

This class is suitable for the common case of logging a key–value pair as parameter to the *f family of logging functions on Logger. For advanced use cases, provide your own implementation of StructuredParameter.

Example:

logger.infof("Application starting.", StructuredParameter.of("version", "1.0"));

Result:

{
  "jsonPayload": {
    "message": "Application starting.",
    "version": "1.0"
  }
}
See Also:
  • Method Details

    • of

      public static KeyValueParameter of(String key, String value)
      Creates a KeyValueParameter from a String value.

      The resulting JSON value is of type string.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, int value)
      Creates a KeyValueParameter from an int value.

      The resulting JSON value is of type number.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, long value)
      Creates a KeyValueParameter from a long value.

      The resulting JSON value is of type number.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, double value)
      Creates a KeyValueParameter from a double value.

      The resulting JSON value is of type number.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, BigDecimal value)
      Creates a KeyValueParameter from a BigDecimal value.

      The resulting JSON value is of type number.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, BigInteger value)
      Creates a KeyValueParameter from a BigInteger value.

      The resulting JSON value is of type number.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • of

      public static KeyValueParameter of(String key, boolean value)
      Creates a KeyValueParameter from a boolean value.

      The resulting JSON value is of type boolean.

      Parameters:
      key - the key part of the key–value pair.
      value - the value part of the key–value pair.
      Returns:
      the newly constructed parameter, ready to be passed to a logging function.
    • json

      public jakarta.json.JsonObjectBuilder json()
      Description copied from interface: StructuredParameter
      The JSON to be embedded in the payload of the log entry.

      May contain multiple keys and values as well as nested objects. Each top-level entry of the returned object is embedded as a top-level entry in the payload of the log entry.

      Specified by:
      json in interface StructuredParameter
      Returns:
      A JsonObjectBuilder holding a set of key–value pairs.
    • key

      public String key()
      The key part of the key–value pair.
      Returns:
      the key part of the key–value pair.
    • value

      public jakarta.json.JsonValue value()
      The value part of the key–value pair.

      Can be of any non-composite JSON type (i.e. string, number, or boolean).

      Returns:
      the value pairt of the key–value pair.
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object