Crates.io | cloudwatch_logging |
lib.rs | cloudwatch_logging |
version | 1.0.0 |
source | src |
created_at | 2023-04-20 18:48:29.216602 |
updated_at | 2023-09-14 04:18:11.985163 |
description | A simple library for logging to AWS CloudWatch Logs |
homepage | |
repository | https://github.com/Omena-Palette/CloudWatchLogging |
max_upload_size | |
id | 844714 |
size | 49,586 |
The CloudWatch Logging crate provides a simple and efficient way to log to Amazon CloudWatch.
Add the following dependency to your Cargo.toml
file:
[dependencies]
cloudwatch-logging = "1.0.0"
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
}
cloudwatch_logging::__doc_test!(example);
Logging Panics
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(())
}
cloudwatch_logging::__doc_test_panics!(example, "This will be logged to cloudwatch!");
singleton
Feature
use cloudwatch_logging::prelude::*;
#[cfg(feature = "singleton")]
async fn example() -> Result<(), LoggerError> {
let logger = LoggerHandle::get_or_setup( // 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
}
#[cfg(feature = "singleton")]
cloudwatch_logging::__doc_test!(example);
singleton
Feature: initializing with environment variables
use cloudwatch_logging::prelude::*;
use std::env;
#[cfg(feature = "singleton")]
async fn example() -> Result<(), LoggerError> {
env::set_var("TEST_GROUP", "test-group");
env::set_var("TEST_STREAM", "test-stream");
let logger = LoggerHandle::get_or_setup_with_env(
"TEST_GROUP", // log group env var
"TEST_STREAM", // log stream env var
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
}
#[cfg(feature = "singleton")]
cloudwatch_logging::__doc_test!(example);
For more information, please refer to the current documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
cloudwatch_logging
is officially stable! While new features will be added, the api will remain the same.
log
crate supporttracing
crate supportLoggerHandle
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.
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.
Running Tests:
Standard Tests:
cargo test --features "doc_tests" -- --test-threads=1
Including Loom Models:
cargo test --features "doc_tests loom" -- --test-threads=1
Stress Tests:
cargo test --features "doc_tests im_ok_paying_for_testing" -- --test-threads=1