Expand description
A Rust library providing slog drains for sending log messages to
cloud-based log storages. The crate implements drains for Loggly and
Better Stack. Drains for custom providers can be easily implemented using
the CloudDrain type.
§Things to be aware of
The Loggly and Better Stack drains serialize all log messages as JSON objects. If you use key-value pairs in your loggers and log messages, you should know that one key-value pair can override another if they both have the same key. The overrides follow this simple rule:
- Derived loggers can override key-value pairs of their ancestors.
- Log messages can override key-value pairs of their loggers.
- The latest specified key-value pair overrides everything specified before.
§Usage
Please note that the drains are asynchronous and the log messages are sent on background. If your application exits, there might be still some log messages in the queue.
§Using the Loggly drain in an asynchronous application
ⓘ
use slog::{debug, error, info, o, warn, Drain, Logger};
use slog_cloud::loggly::LogglyDrainBuilder;
#[tokio::main]
async fn main() {
// Your Loggly token and tag.
let loggly_token = "your-loggly-token";
let loggly_tag = "some-app";
// Create a custom Loggly drain.
let (drain, handle) = LogglyDrainBuilder::new()
.spawn_task(loggly_token, loggly_tag)
.unwrap();
// Create a logger.
let logger = Logger::root(drain.fuse(), o!());
debug!(logger, "debug"; "key" => "value");
info!(logger, "info"; "key" => "value");
warn!(logger, "warn"; "key" => "value");
error!(logger, "error"; "key" => "value");
// Flush all log messages.
handle.flush().await;
}§Using the Loggly drain in a normal application
ⓘ
use slog::{debug, error, info, o, warn, Drain, Logger};
use slog_cloud::loggly::LogglyDrainBuilder;
// Your Loggly token and tag.
let loggly_token = "your-loggly-token";
let loggly_tag = "some-app";
// Create a custom Loggly drain.
let (drain, handle) = LogglyDrainBuilder::new()
.spawn_thread(loggly_token, loggly_tag)
.unwrap();
// Create a logger.
let logger = Logger::root(drain.fuse(), o!());
debug!(logger, "debug"; "key" => "value");
info!(logger, "info"; "key" => "value");
warn!(logger, "warn"; "key" => "value");
error!(logger, "error"; "key" => "value");
// Flush all log messages.
handle.blocking_flush();§Using the Better Stack drain
The Better Stack drain usage is analogous to the Loggly drain.
Modules§
- batch
- bstack
better-stack - client
- loggly
loggly - serializer
Structs§
- Cloud
Drain - Generic cloud log drain.
- Cloud
Drain Builder - Cloud drain builder.
- Cloud
Drain Handle - Handle for a cloud log drain.
- Cloud
Drain Task - Task for a cloud log drain.
- Error
- Error.