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

#81 in Debugging

Download history 11250/week @ 2024-04-04 11187/week @ 2024-04-11 14864/week @ 2024-04-18 15945/week @ 2024-04-25 14031/week @ 2024-05-02 16037/week @ 2024-05-09 18210/week @ 2024-05-16 19429/week @ 2024-05-23 20958/week @ 2024-05-30 16380/week @ 2024-06-06 16619/week @ 2024-06-13 19347/week @ 2024-06-20 19655/week @ 2024-06-27 11246/week @ 2024-07-04 10685/week @ 2024-07-11 9410/week @ 2024-07-18

54,816 downloads per month
Used in 7 crates (6 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

~7–22MB
~281K SLoC