Crate slog_loggly

source ·
Expand description

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:

  1. Derived loggers can override key-value pairs of their ancestors.
  2. Log messages can override key-value pairs of their loggers.
  3. 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();

Structs

Accept all key-value pairs.
Error.
A flush handle that can be used to flush all currently queued log messages.
Loggly drain.
Loggly drain builder.
A future driving the send of all log messages.

Traits

Key-value pair filter.