12 releases
0.6.0 | Jun 19, 2024 |
---|---|
0.5.1 | Dec 13, 2022 |
0.5.0 | Dec 6, 2021 |
0.4.0 | Jul 8, 2020 |
0.1.1 | May 2, 2018 |
#234 in Debugging
43KB
926 lines
Loggly drain for slog
This is an unofficial Loggly drain for the slog logging infrastructure in Rust.
Usage
Add the following dependency into your Cargo.toml:
slog-loggly = "0.6.0"
See the examples
directory and the documentation for usage examples.
lib.rs
:
A Rust library providing an slog drain for sending log messages to Loggly.
Things to be aware of
The drain serializes 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 Loggly drain is 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_loggly::LogglyDrain;
#[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, mut fhandle) = LogglyDrain::builder(loggly_token, loggly_tag)
.spawn_task()
.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");
// You can return the flush handle to make sure that all log
// messages get sent before the process terminates.
// fhandle.async_flush().await.unwrap();
}
Using the Loggly drain in a normal application
use slog::{debug, error, info, o, warn, Drain, Logger};
use slog_loggly::LogglyDrain;
// Your Loggly token and tag.
let loggly_token = "your-loggly-token";
let loggly_tag = "some-app";
// Create a custom Loggly drain.
let (drain, mut fhandle) = LogglyDrain::builder(loggly_token, loggly_tag)
.spawn_thread()
.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");
// You can use the flush handle to make sure that all log messages get
// sent before the process terminates.
// fhandle.blocking_flush().unwrap();
Dependencies
~6–20MB
~308K SLoC