9 releases

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

#67 in Debugging

Download history 16364/week @ 2025-01-11 16956/week @ 2025-01-18 17313/week @ 2025-01-25 21714/week @ 2025-02-01 26258/week @ 2025-02-08 15431/week @ 2025-02-15 14323/week @ 2025-02-22 17610/week @ 2025-03-01 19380/week @ 2025-03-08 19718/week @ 2025-03-15 20039/week @ 2025-03-22 22250/week @ 2025-03-29 19605/week @ 2025-04-05 17514/week @ 2025-04-12 13893/week @ 2025-04-19 12139/week @ 2025-04-26

67,256 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

http://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–20MB
~256K SLoC