9 releases

new 0.2.6 Jan 13, 2025
0.2.5 Jun 12, 2024
0.2.4 Aug 1, 2023
0.2.3 Jun 16, 2023
0.1.0 Mar 22, 2022

#89 in Debugging

Download history 16753/week @ 2024-09-24 15030/week @ 2024-10-01 12656/week @ 2024-10-08 15248/week @ 2024-10-15 13610/week @ 2024-10-22 10149/week @ 2024-10-29 10314/week @ 2024-11-05 7727/week @ 2024-11-12 11122/week @ 2024-11-19 14413/week @ 2024-11-26 16767/week @ 2024-12-03 18558/week @ 2024-12-10 11907/week @ 2024-12-17 1937/week @ 2024-12-24 5224/week @ 2024-12-31 13462/week @ 2025-01-07

35,550 downloads per month
Used in 8 crates (7 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

~9–20MB
~261K SLoC