Crate slog_loggly [−] [src]
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
extern crate futures; #[macro_use] extern crate slog; extern crate slog_loggly; extern crate tokio_core; use slog::{Drain, Logger}; use slog_loggly::LogglyDrain; use tokio_core::reactor::{Core, Handle}; fn main() { // Your Loggly token and tag. let loggly_token = "your-loggly-token"; let loggly_tag = "some-app"; let mut core = Core::new().unwrap(); let handle = core.handle(); // Create a custom Loggly drain. let (drain, mut fhandle) = LogglyDrain::builder(loggly_token, loggly_tag) .spawn_task(&handle) .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. // core.run(fhandle.flush()).unwrap(); }
Using the Loggly drain in a normal application
extern crate futures; #[macro_use] extern crate slog; extern crate slog_loggly; use futures::Future; use slog::{Drain, Logger}; use slog_loggly::LogglyDrain; 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_thread(); // 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.flush().wait().unwrap(); }
Structs
Error |
Error. |
Flush |
Flush future. |
FlushHandle |
A flush handle that can be used to flush all currently queued log messages. |
LogglyDrain |
Loggly drain. |
LogglyDrainBuilder |
Loggly drain builder. |