slog_cloud/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! A Rust library providing slog drains for sending log messages to
4//! cloud-based log storages. The crate implements drains for Loggly and
5//! Better Stack. Drains for custom providers can be easily implemented using
6//! the `CloudDrain` type.
7//!
8//! # Things to be aware of
9//!
10//! The Loggly and Better Stack drains serialize all log messages as JSON
11//! objects. If you use key-value pairs in your loggers and log messages, you
12//! should know that one key-value pair can override another if they both have
13//! the same key. The overrides follow this simple rule:
14//! 1. Derived loggers can override key-value pairs of their ancestors.
15//! 2. Log messages can override key-value pairs of their loggers.
16//! 3. The latest specified key-value pair overrides everything specified
17//! before.
18//!
19//! # Usage
20//!
21//! Please note that the drains are asynchronous and the log messages are
22//! sent on background. If your application exits, there might be still some
23//! log messages in the queue.
24//!
25//! ## Using the Loggly drain in an asynchronous application
26//!
27//! ```ignore
28//! use slog::{debug, error, info, o, warn, Drain, Logger};
29//! use slog_cloud::loggly::LogglyDrainBuilder;
30//!
31//! #[tokio::main]
32//! async fn main() {
33//! // Your Loggly token and tag.
34//! let loggly_token = "your-loggly-token";
35//! let loggly_tag = "some-app";
36//!
37//! // Create a custom Loggly drain.
38//! let (drain, handle) = LogglyDrainBuilder::new()
39//! .spawn_task(loggly_token, loggly_tag)
40//! .unwrap();
41//!
42//! // Create a logger.
43//! let logger = Logger::root(drain.fuse(), o!());
44//!
45//! debug!(logger, "debug"; "key" => "value");
46//! info!(logger, "info"; "key" => "value");
47//! warn!(logger, "warn"; "key" => "value");
48//! error!(logger, "error"; "key" => "value");
49//!
50//! // Flush all log messages.
51//! handle.flush().await;
52//! }
53//! ```
54//!
55//! ## Using the Loggly drain in a normal application
56//!
57//! ```ignore
58//! use slog::{debug, error, info, o, warn, Drain, Logger};
59//! use slog_cloud::loggly::LogglyDrainBuilder;
60//!
61//! // Your Loggly token and tag.
62//! let loggly_token = "your-loggly-token";
63//! let loggly_tag = "some-app";
64//!
65//! // Create a custom Loggly drain.
66//! let (drain, handle) = LogglyDrainBuilder::new()
67//! .spawn_thread(loggly_token, loggly_tag)
68//! .unwrap();
69//!
70//! // Create a logger.
71//! let logger = Logger::root(drain.fuse(), o!());
72//!
73//! debug!(logger, "debug"; "key" => "value");
74//! info!(logger, "info"; "key" => "value");
75//! warn!(logger, "warn"; "key" => "value");
76//! error!(logger, "error"; "key" => "value");
77//!
78//! // Flush all log messages.
79//! handle.blocking_flush();
80//! ```
81//!
82//! ## Using the Better Stack drain
83//!
84//! The Better Stack drain usage is analogous to the Loggly drain.
85
86mod drain;
87mod error;
88mod queue;
89mod sender;
90
91pub mod batch;
92pub mod client;
93pub mod serializer;
94
95#[cfg(feature = "better-stack")]
96#[cfg_attr(docsrs, doc(cfg(feature = "better-stack")))]
97pub mod bstack;
98
99#[cfg(feature = "loggly")]
100#[cfg_attr(docsrs, doc(cfg(feature = "loggly")))]
101pub mod loggly;
102
103pub use self::{
104 drain::{CloudDrain, CloudDrainBuilder, CloudDrainHandle, CloudDrainTask},
105 error::Error,
106};