tracing-loki

A tracing layer for Grafana Loki.

Build status

Documentation

https://docs.rs/tracing-loki

Usage

Add this to your Cargo.toml: toml [dependencies] tracing-loki = "0.1"

Example

```rust use tracingsubscriber::layer::SubscriberExt; use tracingsubscriber::util::SubscriberInitExt; use std::process; use url::Url;

[tokio::main]

async fn main() -> Result<(), tracingloki::Error> { let (layer, task) = tracingloki::builder() .label("host", "mine")? .extrafield("pid", format!("{}", process::id()))? .buildurl(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(())

} ```