Class LogEventBatching

java.lang.Object
codes.grow.packages.cloudwatchlogs.LogEventBatching

public final class LogEventBatching extends Object
Client-side PutLogEvents batching (DECISIONS 5, API.md section 2.2).

CloudWatch Logs rejects a PutLogEvents call with more than 10 000 events, more than 1 048 576 bytes (sum of UTF-8 message bytes + 26 per event), events spanning more than 24 hours or events out of chronological order. These limits are enforced here, before anything is sent.

  • Field Details

    • MAX_EVENTS_PER_BATCH

      public static final int MAX_EVENTS_PER_BATCH
      Most events in one PutLogEvents call.
      See Also:
    • MAX_BATCH_BYTES

      public static final int MAX_BATCH_BYTES
      Most bytes in one PutLogEvents call (sum of UTF-8 message bytes + 26 per event).
      See Also:
    • EVENT_OVERHEAD_BYTES

      public static final int EVENT_OVERHEAD_BYTES
      Bytes AWS adds to every event when it checks the batch size.
      See Also:
    • MAX_BATCH_SPAN_MS

      public static final long MAX_BATCH_SPAN_MS
      Longest time span (last minus first timestamp) of one batch: 24 hours in milliseconds.
      See Also:
  • Method Details

    • utf8Bytes

      public static int utf8Bytes(String text)
      Returns the UTF-8 size of a string in bytes.
      Parameters:
      text - text
      Returns:
      the size
    • truncateMessage

      public static String truncateMessage(String message, int maxBytes)
      Truncates message on a UTF-8 character boundary so the result, including the appended " …[truncated N bytes]" marker, is at most maxBytes UTF-8 bytes. N is the number of bytes removed from the original. Returns message when it already fits.
      Parameters:
      message - the message
      maxBytes - the limit in bytes
      Returns:
      the truncated message
    • plan

      public static LogEventBatching.BatchPlan plan(List<LogEvent> events, int maxEventBytes, OversizePolicy policy)
      Applies the per-event size policy, sorts events by timestamp (stable) and splits them into batches that respect every PutLogEvents limit.
      Parameters:
      events - events in any order
      maxEventBytes - per-event limit (1 to 1 048 550)
      policy - what to do with larger events
      Returns:
      the plan
      Throws:
      ValidationException - for a null event or an oversized event with OversizePolicy.ERROR