Expand description
A tracing
layer for shipping logs to Grafana
Loki.
§Usage
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(())
}
Re-exports§
pub extern crate url;
Structs§
- Background
Task - The background task that ships logs to Loki. It must be
tokio::spawn
ed by the calling application. - Background
Task Controller - Handle to cleanly shut down the
BackgroundTask
. - Builder
- Builder for constructing a
Layer
and its correspondingBackgroundTask
. - Error
- The error type for constructing a
Layer
. - Layer
- The
tracing_subscriber::Layer
implementation for the Loki backend.
Functions§
- builder
- Create a
Builder
for constructing aLayer
and its correspondingBackgroundTask
. - layer
- Construct a
Layer
and its correspondingBackgroundTask
.