4 releases

0.2.2 May 5, 2025
0.2.1 Feb 3, 2025
0.2.0 Sep 30, 2023
0.1.0 Sep 30, 2023

#824 in Debugging

Download history 125/week @ 2025-01-29 70/week @ 2025-02-05 25/week @ 2025-02-12 22/week @ 2025-02-19 3/week @ 2025-02-26 13/week @ 2025-03-12 17/week @ 2025-04-09 91/week @ 2025-04-30 43/week @ 2025-05-07 10/week @ 2025-05-14

144 downloads per month

MIT/Apache

41KB
402 lines

logcontrol-tracing

Crates.io docs.rs

tracing implementation for the logcontrol interface.

Usage

$ 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
    }
}

Dependencies

~4.5–6.5MB
~108K SLoC