CloudWatchLogs class

You can use Amazon CloudWatch Logs to monitor, store, and access your log files from EC2 instances, AWS CloudTrail, or other sources. You can then retrieve the associated log data from CloudWatch Logs using the CloudWatch console, CloudWatch Logs commands in the AWS CLI, CloudWatch Logs API, or CloudWatch Logs SDK.

You can use CloudWatch Logs to:

  • Monitor logs from EC2 instances in real-time: You can use CloudWatch Logs to monitor applications and systems using log data. For example, CloudWatch Logs can track the number of errors that occur in your application logs and send you a notification whenever the rate of errors exceeds a threshold that you specify. CloudWatch Logs uses your log data for monitoring so no code changes are required. For example, you can monitor application logs for specific literal terms (such as "NullReferenceException") or count the number of occurrences of a literal term at a particular position in log data (such as "404" status codes in an Apache access log). When the term you are searching for is found, CloudWatch Logs reports the data to a CloudWatch metric that you specify.
  • Monitor AWS CloudTrail logged events: You can create alarms in CloudWatch and receive notifications of particular API activity as captured by CloudTrail. You can use the notification to perform troubleshooting.
  • Archive log data: You can use CloudWatch Logs to store your log data in highly durable storage. You can change the log retention setting so that any log events older than this setting are automatically deleted. The CloudWatch Logs agent makes it easy to quickly send both rotated and non-rotated log data off of a host and into the log service. You can then access the raw log data when you need it.

Constructors

CloudWatchLogs({required String region, AwsClientCredentials? credentials, AwsClientCredentialsProvider? credentialsProvider, Client? client, String? endpointUrl})

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

associateKmsKey({required String kmsKeyId, required String logGroupName}) Future<void>
Associates the specified AWS Key Management Service (AWS KMS) customer master key (CMK) with the specified log group.
cancelExportTask({required String taskId}) Future<void>
Cancels the specified export task.
close() → void
Closes the internal HTTP client if none was provided at creation. If a client was passed as a constructor argument, this becomes a noop.
createExportTask({required String destination, required int from, required String logGroupName, required int to, String? destinationPrefix, String? logStreamNamePrefix, String? taskName}) Future<CreateExportTaskResponse>
Creates an export task, which allows you to efficiently export data from a log group to an Amazon S3 bucket. When you perform a CreateExportTask operation, you must use credentials that have permission to write to the S3 bucket that you specify as the destination.
createLogGroup({required String logGroupName, String? kmsKeyId, Map<String, String>? tags}) Future<void>
Creates a log group with the specified name. You can create up to 20,000 log groups per account.
createLogStream({required String logGroupName, required String logStreamName}) Future<void>
Creates a log stream for the specified log group. A log stream is a sequence of log events that originate from a single source, such as an application instance or a resource that is being monitored.
deleteDestination({required String destinationName}) Future<void>
Deletes the specified destination, and eventually disables all the subscription filters that publish to it. This operation does not delete the physical resource encapsulated by the destination.
deleteLogGroup({required String logGroupName}) Future<void>
Deletes the specified log group and permanently deletes all the archived log events associated with the log group.
deleteLogStream({required String logGroupName, required String logStreamName}) Future<void>
Deletes the specified log stream and permanently deletes all the archived log events associated with the log stream.
deleteMetricFilter({required String filterName, required String logGroupName}) Future<void>
Deletes the specified metric filter.
deleteQueryDefinition({required String queryDefinitionId}) Future<DeleteQueryDefinitionResponse>
Deletes a saved CloudWatch Logs Insights query definition. A query definition contains details about a saved CloudWatch Logs Insights query.
deleteResourcePolicy({String? policyName}) Future<void>
Deletes a resource policy from this account. This revokes the access of the identities in that policy to put log events to this account.
deleteRetentionPolicy({required String logGroupName}) Future<void>
Deletes the specified retention policy.
deleteSubscriptionFilter({required String filterName, required String logGroupName}) Future<void>
Deletes the specified subscription filter.
describeDestinations({String? destinationNamePrefix, int? limit, String? nextToken}) Future<DescribeDestinationsResponse>
Lists all your destinations. The results are ASCII-sorted by destination name.
describeExportTasks({int? limit, String? nextToken, ExportTaskStatusCode? statusCode, String? taskId}) Future<DescribeExportTasksResponse>
Lists the specified export tasks. You can list all your export tasks or filter the results based on task ID or task status.
describeLogGroups({int? limit, String? logGroupNamePrefix, String? nextToken}) Future<DescribeLogGroupsResponse>
Lists the specified log groups. You can list all your log groups or filter the results by prefix. The results are ASCII-sorted by log group name.
describeLogStreams({required String logGroupName, bool? descending, int? limit, String? logStreamNamePrefix, String? nextToken, OrderBy? orderBy}) Future<DescribeLogStreamsResponse>
Lists the log streams for the specified log group. You can list all the log streams or filter the results by prefix. You can also control how the results are ordered.
describeMetricFilters({String? filterNamePrefix, int? limit, String? logGroupName, String? metricName, String? metricNamespace, String? nextToken}) Future<DescribeMetricFiltersResponse>
Lists the specified metric filters. You can list all of the metric filters or filter the results by log name, prefix, metric name, or metric namespace. The results are ASCII-sorted by filter name.
describeQueries({String? logGroupName, int? maxResults, String? nextToken, QueryStatus? status}) Future<DescribeQueriesResponse>
Returns a list of CloudWatch Logs Insights queries that are scheduled, executing, or have been executed recently in this account. You can request all queries or limit it to queries of a specific log group or queries with a certain status.
describeQueryDefinitions({int? maxResults, String? nextToken, String? queryDefinitionNamePrefix}) Future<DescribeQueryDefinitionsResponse>
This operation returns a paginated list of your saved CloudWatch Logs Insights query definitions.
describeResourcePolicies({int? limit, String? nextToken}) Future<DescribeResourcePoliciesResponse>
Lists the resource policies in this account.
describeSubscriptionFilters({required String logGroupName, String? filterNamePrefix, int? limit, String? nextToken}) Future<DescribeSubscriptionFiltersResponse>
Lists the subscription filters for the specified log group. You can list all the subscription filters or filter the results by prefix. The results are ASCII-sorted by filter name.
disassociateKmsKey({required String logGroupName}) Future<void>
Disassociates the associated AWS Key Management Service (AWS KMS) customer master key (CMK) from the specified log group.
filterLogEvents({required String logGroupName, int? endTime, String? filterPattern, bool? interleaved, int? limit, String? logStreamNamePrefix, List<String>? logStreamNames, String? nextToken, int? startTime}) Future<FilterLogEventsResponse>
Lists log events from the specified log group. You can list all the log events or filter the results using a filter pattern, a time range, and the name of the log stream.
getLogEvents({required String logGroupName, required String logStreamName, int? endTime, int? limit, String? nextToken, bool? startFromHead, int? startTime}) Future<GetLogEventsResponse>
Lists log events from the specified log stream. You can list all of the log events or filter using a time range.
getLogGroupFields({required String logGroupName, int? time}) Future<GetLogGroupFieldsResponse>
Returns a list of the fields that are included in log events in the specified log group, along with the percentage of log events that contain each field. The search is limited to a time period that you specify.
getLogRecord({required String logRecordPointer}) Future<GetLogRecordResponse>
Retrieves all of the fields and values of a single log event. All fields are retrieved, even if the original query that produced the logRecordPointer retrieved only a subset of fields. Fields are returned as field name/field value pairs.
getQueryResults({required String queryId}) Future<GetQueryResultsResponse>
Returns the results from the specified query.
listTagsLogGroup({required String logGroupName}) Future<ListTagsLogGroupResponse>
Lists the tags for the specified log group.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
putDestination({required String destinationName, required String roleArn, required String targetArn}) Future<PutDestinationResponse>
Creates or updates a destination. This operation is used only to create destinations for cross-account subscriptions.
putDestinationPolicy({required String accessPolicy, required String destinationName}) Future<void>
Creates or updates an access policy associated with an existing destination. An access policy is an IAM policy document that is used to authorize claims to register a subscription filter against a given destination.
putLogEvents({required List<InputLogEvent> logEvents, required String logGroupName, required String logStreamName, String? sequenceToken}) Future<PutLogEventsResponse>
Uploads a batch of log events to the specified log stream.
putMetricFilter({required String filterName, required String filterPattern, required String logGroupName, required List<MetricTransformation> metricTransformations}) Future<void>
Creates or updates a metric filter and associates it with the specified log group. Metric filters allow you to configure rules to extract metric data from log events ingested through PutLogEvents.
putQueryDefinition({required String name, required String queryString, List<String>? logGroupNames, String? queryDefinitionId}) Future<PutQueryDefinitionResponse>
Creates or updates a query definition for CloudWatch Logs Insights. For more information, see Analyzing Log Data with CloudWatch Logs Insights.
putResourcePolicy({String? policyDocument, String? policyName}) Future<PutResourcePolicyResponse>
Creates or updates a resource policy allowing other AWS services to put log events to this account, such as Amazon Route 53. An account can have up to 10 resource policies per AWS Region.
putRetentionPolicy({required String logGroupName, required int retentionInDays}) Future<void>
Sets the retention of the specified log group. A retention policy allows you to configure the number of days for which to retain log events in the specified log group.
putSubscriptionFilter({required String destinationArn, required String filterName, required String filterPattern, required String logGroupName, Distribution? distribution, String? roleArn}) Future<void>
Creates or updates a subscription filter and associates it with the specified log group. Subscription filters allow you to subscribe to a real-time stream of log events ingested through PutLogEvents and have them delivered to a specific destination. When log events are sent to the receiving service, they are Base64 encoded and compressed with the gzip format.
startQuery({required int endTime, required String queryString, required int startTime, int? limit, String? logGroupName, List<String>? logGroupNames}) Future<StartQueryResponse>
Schedules a query of a log group using CloudWatch Logs Insights. You specify the log group and time range to query and the query string to use.
stopQuery({required String queryId}) Future<StopQueryResponse>
Stops a CloudWatch Logs Insights query that is in progress. If the query has already ended, the operation returns an error indicating that the specified query is not running.
tagLogGroup({required String logGroupName, required Map<String, String> tags}) Future<void>
Adds or updates the specified tags for the specified log group.
testMetricFilter({required String filterPattern, required List<String> logEventMessages}) Future<TestMetricFilterResponse>
Tests the filter pattern of a metric filter against a sample of log event messages. You can use this operation to validate the correctness of a metric filter pattern.
toString() String
A string representation of this object.
inherited
untagLogGroup({required String logGroupName, required List<String> tags}) Future<void>
Removes the specified tags from the specified log group.

Operators

operator ==(Object other) bool
The equality operator.
inherited