#logging #slog #loggly

slog-loggly

This is an unofficial Loggly drain for the slog logging infrastructure in Rust

10 releases

0.5.0 Dec 6, 2021
0.4.0 Jul 8, 2020
0.3.2 Jun 20, 2019
0.3.0 Aug 29, 2018
0.1.1 May 2, 2018

#149 in Debugging

Download history 108/week @ 2022-05-31 63/week @ 2022-06-07 28/week @ 2022-06-14 24/week @ 2022-06-21 32/week @ 2022-06-28 23/week @ 2022-07-05 12/week @ 2022-07-12 31/week @ 2022-07-19 24/week @ 2022-07-26 40/week @ 2022-08-02 23/week @ 2022-08-09 10/week @ 2022-08-16 26/week @ 2022-08-23 64/week @ 2022-08-30 31/week @ 2022-09-06 76/week @ 2022-09-13

198 downloads per month

MIT/Apache

43KB
901 lines

Loggly drain for slog

Crates.io Documentation Build Status

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.5"

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:

  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();

Dependencies

~6–13MB
~215K SLoC