Crates.io | tracing-loki |
lib.rs | tracing-loki |
version | 0.2.5 |
source | src |
created_at | 2022-03-19 18:10:07.134978 |
updated_at | 2024-06-12 09:44:53.139778 |
description | A tracing layer for shipping logs to Grafana Loki |
homepage | |
repository | https://github.com/hrxi/tracing-loki |
max_upload_size | |
id | 553271 |
size | 89,713 |
A tracing layer for Grafana Loki.
Add this to your Cargo.toml
:
[dependencies]
tracing-loki = "0.1"
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(())
}