8 releases

0.2.5 Jun 12, 2024
0.2.4 Aug 1, 2023
0.2.3 Jun 16, 2023
0.2.2 Mar 8, 2023
0.0.0 Mar 19, 2022

#101 in Debugging

Download history 10603/week @ 2024-08-12 14581/week @ 2024-08-19 14322/week @ 2024-08-26 16420/week @ 2024-09-02 15257/week @ 2024-09-09 12307/week @ 2024-09-16 16770/week @ 2024-09-23 14825/week @ 2024-09-30 13395/week @ 2024-10-07 14378/week @ 2024-10-14 13839/week @ 2024-10-21 10858/week @ 2024-10-28 11167/week @ 2024-11-04 6910/week @ 2024-11-11 10729/week @ 2024-11-18 13726/week @ 2024-11-25

42,865 downloads per month
Used in 9 crates (8 directly)

MIT/Apache

57KB
1K SLoC

tracing-loki

A tracing layer for Grafana Loki.

Build status

Documentation

https://docs.rs/tracing-loki

Usage

Add this to your Cargo.toml:

[dependencies]
tracing-loki = "0.1"

Example

use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use std::process;
use url::Url;

#[tokio::main]
async fn main() -> Result<(), tracing_loki::Error> {
    let (layer, task) = tracing_loki::builder()
        .label("host", "mine")?
        .extra_field("pid", format!("{}", process::id()))?
        .build_url(Url::parse("http://127.0.0.1:3100").unwrap())?;

    // We need to register our layer with `tracing`.
    tracing_subscriber::registry()
        .with(layer)
        // One could add more layers here, for example logging to stdout:
        // .with(tracing_subscriber::fmt::Layer::new())
        .init();

    // The background task needs to be spawned so the logs actually get
    // delivered.
    tokio::spawn(task);

    tracing::info!(
        task = "tracing_setup",
        result = "success",
        "tracing successfully set up",
    );

    Ok(())
}

Dependencies

~8–19MB
~252K SLoC