10 releases

new 0.3.1 Aug 1, 2020
0.3.0 Jul 2, 2020
0.2.3 May 19, 2020
0.2.1 Feb 6, 2020
0.1.0 Dec 23, 2019

#79 in Development tools

Download history 31/week @ 2020-04-13 8/week @ 2020-04-20 1/week @ 2020-04-27 10/week @ 2020-05-04 56/week @ 2020-05-11 60/week @ 2020-05-18 12/week @ 2020-05-25 35/week @ 2020-06-01 9/week @ 2020-06-08 79/week @ 2020-06-15 42/week @ 2020-06-22 28/week @ 2020-06-29 68/week @ 2020-07-06 98/week @ 2020-07-13 22/week @ 2020-07-20 20/week @ 2020-07-27

176 downloads per month

MIT license

27KB
428 lines

tracing-gelf

A Graylog tracing library.

Build Status License Cargo Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
tracing-gelf = "0.3"

TCP Logging

use std::net::SocketAddr;
use tracing_gelf::Logger;

#[tokio::main]
async fn main() {
    // Graylog address
    let address: SocketAddr = "127.0.0.1:12201".parse().unwrap();

    // Start tracing
    let bg_task = Logger::builder().init_tcp(address).unwrap();

    // Spawn background task
    // Any futures executor can be used
    tokio::spawn(bg_task);

    // Send a log to Graylog
    tracing::info!(message = "oooh, what's in here?");

    // Create a span
    let span = tracing::info_span!("cave");
    span.in_scope(|| {
        // Log inside a span
        let test = tracing::info_span!("deeper in cave", smell = "damp");
        test.in_scope(|| {
            tracing::warn!(message = "oh god, it's dark in here");
        })
    });

    // Log a structured log
    tracing::error!(message = "i'm glad to be out", spook_lvl = 3, ruck_sack = ?["glasses", "inhaler", "large bat"]);
}

UDP Logging

use std::net::SocketAddr;
use tracing_gelf::Logger;

#[tokio::main]
async fn main() {
    // Graylog address
    let address: SocketAddr = "127.0.0.1:12202".parse().unwrap();

    // Start tracing
    let bg_task = Logger::builder().init_udp(address).unwrap();

    // Spawn background task
    // Any futures executor can be used
    tokio::spawn(bg_task);

    // Send a log to Graylog
    tracing::info!(message = "our dreams feel real while we're in them");

    // Create a span
    let span = tracing::info_span!("level 1");
    span.in_scope(|| {
        // Log inside a span
        tracing::warn!(message = "we need to go deeper", music = "hans zimmer");

        // Create an nested span
        let inner_span = tracing::info_span!("level 5");
        inner_span.in_scope(|| {
            // Log inside nested span
            tracing::error!(message = "you killed me");
        });
    });

    // Log a structured log
    tracing::info!(message = "he's out", spinning_top = true);
}

Dependencies

~5.5MB
~106K SLoC