Crates.io | logcontrol-tracing |
lib.rs | logcontrol-tracing |
version | 0.2.2 |
created_at | 2023-09-30 12:26:01.526889+00 |
updated_at | 2025-05-05 19:53:50.207377+00 |
description | Tracing backend for the log control interface |
homepage | https://codeberg.org/swsnr/logcontrol.rs |
repository | https://codeberg.org/swsnr/logcontrol.rs.git |
max_upload_size | |
id | 988612 |
size | 56,576 |
tracing
implementation for the logcontrol interface.
$ cargo add logcontrol-tracing
use std::error::Error;
use logcontrol_tracing::{PrettyLogControl1LayerFactory, TracingLogControl1};
use logcontrol_zbus::ConnectionBuilderExt;
use tracing::{event, Level};
use tracing_subscriber::prelude::*;
use tracing_subscriber::Registry;
use zbus::ConnectionBuilder;
#[async_std::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Setup env filter for convenient log control on console
let env_filter = tracing_subscriber::EnvFilter::try_from_default_env().ok();
// If an env filter is set with $RUST_LOG use the lowest level as default for the control part,
// to make sure the env filter takes precedence initially.
let default_level = if env_filter.is_some() {
Level::TRACE
} else {
Level::INFO
};
let (control, control_layer) =
TracingLogControl1::new_auto(PrettyLogControl1LayerFactory, default_level)?;
let subscriber = Registry::default().with(env_filter).with(control_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
let _conn = ConnectionBuilder::session()?
.name("de.swsnr.logcontrol.TracingServerExample")?
.serve_log_control(logcontrol_zbus::LogControl1::new(control))?
.build()
.await?;
loop {
// Service event loop
}
}