Class StructuredArguments

java.lang.Object
software.amazon.lambda.powertools.logging.argument.StructuredArguments

public class StructuredArguments extends Object
Factory for creating StructuredArguments. Inspired from the StructuredArgument of logstash-logback-encoder.
  • Method Details

    • entry

      public static StructuredArgument entry(String key, Object value)
      Adds "key": "value" to the JSON structure and "key=value" to the formatted message. Returns null if the key is a reserved key.
      Parameters:
      key - the field name
      value - the value associated with the key (can be any kind of object)
      Returns:
      a StructuredArgument populated with the data, or null if key is reserved
    • entries

      public static StructuredArgument entries(Map<?,?> map)
      Adds a "key": "value" to the JSON structure for each entry in the map and map.toString() to the formatted message. If the map contains any reserved keys, those entries will be filtered out.
      Parameters:
      map - Map holding the key/value pairs
      Returns:
      a MapArgument populated with the data, with reserved keys filtered out
    • array

      public static StructuredArgument array(String key, Object... values)
      Adds a field to the JSON structure with key as the key and where value is a JSON array of objects AND a string version of the array to the formatted message: "key": [value, value] Returns null if the key is a reserved key.
      Parameters:
      key - the field name
      values - elements of the array associated with the key
      Returns:
      an ArrayArgument populated with the data, or null if key is reserved
    • json

      public static StructuredArgument json(String key, String rawJson)
      Adds the rawJson to the JSON structure and the rawJson to the formatted message. Returns null if the key is a reserved key.
      Parameters:
      key - the field name
      rawJson - the raw JSON String
      Returns:
      a JsonArgument populated with the data, or null if key is reserved
    • toString

      public static String toString(Object arg)
      Format the argument into a string. This method mimics the slf4j behavior: array objects are formatted as array using Arrays.toString(long[]), non array object using String.valueOf(java.lang.Object).

      See org.slf4j.helpers.MessageFormatter#deeplyAppendParameter(StringBuilder, Object, Map)}

      Parameters:
      arg - the argument to format
      Returns:
      formatted string version of the argument