22 releases

0.9.0 Jul 21, 2024
0.8.1 May 21, 2024
0.8.0 Dec 28, 2023
0.7.1 Oct 2, 2022
0.2.0 Dec 23, 2019

#296 in Development tools

Download history 287/week @ 2024-08-14 682/week @ 2024-08-21 939/week @ 2024-08-28 666/week @ 2024-09-04 432/week @ 2024-09-11 469/week @ 2024-09-18 833/week @ 2024-09-25 552/week @ 2024-10-02 339/week @ 2024-10-09 420/week @ 2024-10-16 510/week @ 2024-10-23 427/week @ 2024-10-30 253/week @ 2024-11-06 213/week @ 2024-11-13 192/week @ 2024-11-20 183/week @ 2024-11-27

907 downloads per month
Used in quickjs_runtime

MIT license

37KB
688 lines

tracing-gelf

A Graylog tracing library.

CI License Cargo Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
tracing-gelf = "0.8.0"

TCP Logging

use tracing_gelf::Logger;

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

    // Initialize subscriber
    let conn_handle = Logger::builder().init_tcp(address).unwrap();

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

    // 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(|| {
        let test = tracing::info_span!("deeper in cave", smell = "damp");
        test.in_scope(|| {
            // Send a log to Graylog, inside a nested span
            tracing::warn!(message = "oh god, it's dark in here");
        })
    });

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

UDP Logging

use tracing_gelf::Logger;

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

    // 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–34MB
~518K SLoC