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:

  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

extern crate futures;

#[macro_use]
extern crate slog;
extern crate slog_loggly;
extern crate tokio;

use futures::Future;

use slog::{Drain, Logger};

use slog_loggly::LogglyDrain;

use tokio::runtime::Runtime;

fn main() {
    // Your Loggly token and tag.
    let loggly_token = "your-loggly-token";
    let loggly_tag = "some-app";

    let mut runtime = Runtime::new().unwrap();

    let app = futures::future::lazy(move || {
        // 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.flush()

        futures::future::ok(())
    });

    let res: Result<(), ()> = runtime.block_on(app);

    res.unwrap();

    // We could just use `tokio::run(app)`, however, it would block the
    // thread forever as it waits for the runtime to become idle. (The
    // backgroud task for sending log messages never terminates.)
    runtime.shutdown_now()
        .wait()
        .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()
        .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.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.

LogglyMessageSender

A future driving the send of all log messages.