Crate rusoto_logs
source · [−]Expand description
You can use Amazon CloudWatch Logs to monitor, store, and access your log files from EC2 instances, AWS CloudTrail, and 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.
If you’re using the service, you’re probably looking for CloudWatchLogsClient and CloudWatchLogs.
Examples
Put Log Events
The following code shows a simple example of using Rusoto’s CloudWatchLogs API to send a single log event to the ‘testing’ log stream in the ‘testing’ log group.
use chrono::Utc;
use rusoto_core::Region;
use rusoto_logs::{
CloudWatchLogs, CloudWatchLogsClient, DescribeLogStreamsRequest, InputLogEvent,
PutLogEventsRequest,
};
use std::default::Default;
#[tokio::main]
async fn main() {
const LOG_GROUP_NAME: &str = "testing";
const LOG_STREAM_NAME: &str = "testing";
let client = CloudWatchLogsClient::new(Region::UsEast2);
let input_log_event = InputLogEvent {
message: "Test log message".to_string(),
timestamp: Utc::now().timestamp_millis(), // milliseconds epoch
};
// We need the log stream to get the sequence token
let mut desc_streams_req: DescribeLogStreamsRequest = Default::default();
desc_streams_req.log_group_name = LOG_GROUP_NAME.to_string();
let streams_resp = client.describe_log_streams(desc_streams_req).await;
let log_streams = streams_resp.unwrap().log_streams.unwrap();
let stream = &log_streams
.iter()
.find(|s| s.log_stream_name == Some(LOG_STREAM_NAME.to_string()))
.unwrap();
let sequence_token = stream.upload_sequence_token.clone();
let put_log_events_request = PutLogEventsRequest {
log_events: vec![input_log_event], // > 1 must sort by timestamp ASC
log_group_name: LOG_GROUP_NAME.to_string(),
log_stream_name: LOG_STREAM_NAME.to_string(),
sequence_token,
};
let resp = client.put_log_events(put_log_events_request).await;
println!("{:#?}", resp);
}
Structs
A client for the Amazon CloudWatch Logs API.
Represents a cross-account destination that receives subscription log events.
Represents an export task.
Represents the status of an export task.
Represents the status of an export task.
Represents a matched event.
Represents a log event, which is a record of activity that was recorded by the application or resource being monitored.
Represents a log group.
The fields contained in log events found by a GetLogGroupFields
operation, along with the percentage of queried log events in which each field appears.
Represents a log stream, which is a sequence of log events from a single emitter of logs.
Metric filters express how CloudWatch Logs would extract metric observations from ingested log events and transform them into metric data in a CloudWatch metric.
Represents a matched event.
Indicates how to transform ingested log events to metric data in a CloudWatch metric.
Represents a log event.
Reserved.
Reserved.
This structure contains details about a saved CloudWatch Logs Insights query definition.
Information about one CloudWatch Logs Insights query that matches the request in a DescribeQueries
operation.
Contains the number of log events scanned by the query, the number of log events that matched the query criteria, and the total number of bytes in the log events that were scanned.
Represents the rejected events.
A policy enabling one or more entities to put logs to a log group in this account.
Contains one field from one log event returned by a CloudWatch Logs Insights query, along with the value of that field.
For more information about the fields that are generated by CloudWatch logs, see Supported Logs and Discovered Fields.
Represents the search status of a log stream.
Represents a subscription filter.
Enums
Errors returned by AssociateKmsKey
Errors returned by CancelExportTask
Errors returned by CreateExportTask
Errors returned by CreateLogGroup
Errors returned by CreateLogStream
Errors returned by DeleteDestination
Errors returned by DeleteLogGroup
Errors returned by DeleteLogStream
Errors returned by DeleteMetricFilter
Errors returned by DeleteQueryDefinition
Errors returned by DeleteResourcePolicy
Errors returned by DeleteRetentionPolicy
Errors returned by DeleteSubscriptionFilter
Errors returned by DescribeDestinations
Errors returned by DescribeExportTasks
Errors returned by DescribeLogGroups
Errors returned by DescribeLogStreams
Errors returned by DescribeMetricFilters
Errors returned by DescribeQueries
Errors returned by DescribeQueryDefinitions
Errors returned by DescribeResourcePolicies
Errors returned by DescribeSubscriptionFilters
Errors returned by DisassociateKmsKey
Errors returned by FilterLogEvents
Errors returned by GetLogEvents
Errors returned by GetLogGroupFields
Errors returned by GetLogRecord
Errors returned by GetQueryResults
Errors returned by ListTagsLogGroup
Errors returned by PutDestination
Errors returned by PutDestinationPolicy
Errors returned by PutLogEvents
Errors returned by PutMetricFilter
Errors returned by PutQueryDefinition
Errors returned by PutResourcePolicy
Errors returned by PutRetentionPolicy
Errors returned by PutSubscriptionFilter
Errors returned by StartQuery
Errors returned by StopQuery
Errors returned by TagLogGroup
Errors returned by TestMetricFilter
Errors returned by UntagLogGroup
Traits
Trait representing the capabilities of the Amazon CloudWatch Logs API. Amazon CloudWatch Logs clients implement this trait.