logcontrol-tracing

Crates.iologcontrol-tracing
lib.rslogcontrol-tracing
version0.2.2
created_at2023-09-30 12:26:01.526889+00
updated_at2025-05-05 19:53:50.207377+00
descriptionTracing backend for the log control interface
homepagehttps://codeberg.org/swsnr/logcontrol.rs
repositoryhttps://codeberg.org/swsnr/logcontrol.rs.git
max_upload_size
id988612
size56,576
(swsnr)

documentation

https://docs.rs/logcontrol-tracing

README

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
    }
}
Commit count: 0

cargo fmt