7 releases

0.2.4 Aug 1, 2023
0.2.3 Jun 16, 2023
0.2.2 Mar 8, 2023
0.2.1 Jul 2, 2022
0.0.0 Mar 19, 2022

#95 in Debugging

Download history 9045/week @ 2024-01-15 9501/week @ 2024-01-22 8736/week @ 2024-01-29 4939/week @ 2024-02-05 7627/week @ 2024-02-12 8340/week @ 2024-02-19 7972/week @ 2024-02-26 8996/week @ 2024-03-04 10370/week @ 2024-03-11 8974/week @ 2024-03-18 8651/week @ 2024-03-25 8795/week @ 2024-04-01 10264/week @ 2024-04-08 12506/week @ 2024-04-15 14862/week @ 2024-04-22 17710/week @ 2024-04-29

55,475 downloads per month
Used in 4 crates

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–24MB
~339K SLoC