The CloudWatch Logging SDK for Rust provides a simple and efficient way to log to Amazon CloudWatch Logs.
Add the following dependency to your Cargo.toml
file:
toml
[dependencies]
cloudwatch-logging = "0.2.4"
LoggerHandle
instead of Logger
Logger::get
is now LoggerHandle::get_or_setup
with the singleton
feature enabledThe api is now stable and will not change unless there is a major version bump. Migrating to the new version requires very little effort, everything remained the same outside the entry point.
```rust use cloudwatch_logging::prelude::*;
async fn example() -> Result<(), LoggerError> { let logger = LoggerHandle::setup( "test-group", // log group "test-stream", // log stream 20, // batch size Duration::from_secs(5), // flush interval ).await?;
logger.info("Hello, world!".to_string()).await?;
logger.error("Something went wrong!".to_string()).await
}
cloudwatchlogging::doctest!(example); ```
singleton
Feature
```rust
use cloudwatch_logging::prelude::*;
async fn example() -> Result<(), LoggerError> { let logger = LoggerHandle::getorsetup( // will only setup once "test-group", // log group "test-stream", // log stream 20, // batch size Duration::from_secs(5), // flush interval ).await?;
logger.info("Hello, world!".to_string()).await?;
logger.error("Something went wrong!".to_string()).await
}
cloudwatchlogging::doctest!(example); ```
Logging Panics
```rust use cloudwatch_logging::prelude::*;
async fn example() -> Result<(), LoggerError> { let logger = LoggerHandle::setup( "test-group", // log group "test-stream", // log stream 20, // batch size Duration::from_secs(5), // flush interval ).await?;
logger.log_panics(); // future panics will be logged to cloudwatch
panic!("This will be logged to cloudwatch!");
Ok(())
}
cloudwatchlogging::doctest_panics!(example, "This will be logged to cloudwatch!"); ```
This project is licensed under the MIT License - see the LICENSE file for details.
We'd like to acknowledge the incredible work of the Rusoto community for their AWS SDK, their thoughtful implementation of Smithy, and their dedication to the Rust community.
Rusoto is no longer maintained, although, it is still appropriate for and used in production environments. Once the official AWS SDK for Rust is stable, this crate will be updated to use it instead.