22 个版本

0.9.0 2024年7月21日
0.8.1 2024年5月21日
0.8.0 2023年12月28日
0.7.1 2022年10月2日
0.2.0 2019年12月23日

#251开发工具

Download history 7290/week @ 2024-05-03 7556/week @ 2024-05-10 7694/week @ 2024-05-17 7121/week @ 2024-05-24 301/week @ 2024-05-31 1035/week @ 2024-06-07 4374/week @ 2024-06-14 567/week @ 2024-06-21 305/week @ 2024-06-28 226/week @ 2024-07-05 369/week @ 2024-07-12 816/week @ 2024-07-19 560/week @ 2024-07-26 376/week @ 2024-08-02 220/week @ 2024-08-09 261/week @ 2024-08-16

1,638 每月下载量
quickjs_runtime 中使用

MIT 许可证

37KB
688

tracing-gelf

Graylog tracing 库。

CI License Cargo Documentation

用法

将以下内容添加到您的 Cargo.toml

[dependencies]
tracing-gelf = "0.8.0"

TCP 日志记录

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 日志记录

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

依赖关系

~5–34MB
~518K SLoC