getLogEvents method

Future<GetLogEventsResponse> getLogEvents({
  1. required String logGroupName,
  2. required String logStreamName,
  3. int? endTime,
  4. int? limit,
  5. String? nextToken,
  6. bool? startFromHead,
  7. int? startTime,
})

Lists log events from the specified log stream. You can list all of the log events or filter using a time range.

By default, this operation returns as many log events as can fit in a response size of 1MB (up to 10,000 log events). You can get additional log events by specifying one of the tokens in a subsequent call. This operation can return empty results while there are more log events available through the token.

May throw InvalidParameterException. May throw ResourceNotFoundException. May throw ServiceUnavailableException.

Parameter logGroupName : The name of the log group.

Parameter logStreamName : The name of the log stream.

Parameter endTime : The end of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp equal to or later than this time are not included.

Parameter limit : The maximum number of log events returned. If you don't specify a value, the maximum is as many log events as can fit in a response size of 1 MB, up to 10,000 log events.

Parameter nextToken : The token for the next set of items to return. (You received this token from a previous call.)

Using this token works only when you specify true for startFromHead.

Parameter startFromHead : If the value is true, the earliest log events are returned first. If the value is false, the latest log events are returned first. The default value is false.

If you are using nextToken in this operation, you must specify true for startFromHead.

Parameter startTime : The start of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp equal to this time or later than this time are included. Events with a timestamp earlier than this time are not included.

Implementation

Future<GetLogEventsResponse> getLogEvents({
  required String logGroupName,
  required String logStreamName,
  int? endTime,
  int? limit,
  String? nextToken,
  bool? startFromHead,
  int? startTime,
}) async {
  ArgumentError.checkNotNull(logGroupName, 'logGroupName');
  _s.validateStringLength(
    'logGroupName',
    logGroupName,
    1,
    512,
    isRequired: true,
  );
  ArgumentError.checkNotNull(logStreamName, 'logStreamName');
  _s.validateStringLength(
    'logStreamName',
    logStreamName,
    1,
    512,
    isRequired: true,
  );
  _s.validateNumRange(
    'endTime',
    endTime,
    0,
    1152921504606846976,
  );
  _s.validateNumRange(
    'limit',
    limit,
    1,
    10000,
  );
  _s.validateStringLength(
    'nextToken',
    nextToken,
    1,
    1152921504606846976,
  );
  _s.validateNumRange(
    'startTime',
    startTime,
    0,
    1152921504606846976,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Logs_20140328.GetLogEvents'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'logGroupName': logGroupName,
      'logStreamName': logStreamName,
      if (endTime != null) 'endTime': endTime,
      if (limit != null) 'limit': limit,
      if (nextToken != null) 'nextToken': nextToken,
      if (startFromHead != null) 'startFromHead': startFromHead,
      if (startTime != null) 'startTime': startTime,
    },
  );

  return GetLogEventsResponse.fromJson(jsonResponse.body);
}