#dbus #zbus #systemd #log #logging

logcontrol-zbus

zbus-based DBus frontend for the logcontrol interface

4 stable releases

3.0.0 Nov 1, 2024
2.0.0 Feb 13, 2024
1.1.0 Sep 30, 2023
1.0.0 Sep 30, 2023

#359 in Debugging

Download history 8/week @ 2024-09-16 50/week @ 2024-09-23 28/week @ 2024-09-30 40/week @ 2024-10-07 13/week @ 2024-10-14 135/week @ 2024-10-28 19/week @ 2024-11-04 10/week @ 2024-11-18 73/week @ 2024-12-09

83 downloads per month

MIT/Apache

30KB
215 lines

logcontrol-zbus

Crates.io docs.rs

zbus DBus frontend for the logcontrol interface.

Usage

$ cargo add logcontrol-zbus
use logcontrol_zbus::ConnectionBuilderExt;

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Use an implementation such as logcontrol-tracing
    let control = create_log_control();
    let _conn = zbus::ConnectionBuilder::session()?
        .name("de.swsnr.logcontrol.SimpleServerExample")?
        .serve_log_control(logcontrol_zbus::LogControl1::new(control))?
        .build()
        .await?;

    // Do other things or go to wait forever
    std::future::pending::<()>().await;

    Ok(())
}

lib.rs:

A logcontrol::LogControl1 frontend with zbus.

LogControl1 provides the DBus interface implementation. It receives the underlying logcontrol::LogControl1 as sole argument and exposes it over DBus, as a standard zbus DBus interface:

use logcontrol_zbus::{LogControl1, ConnectionBuilderExt};

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let control = create_log_control();
    let _conn = zbus::ConnectionBuilder::session()?
        .name("de.swsnr.logcontrol.SimpleServerExample")?
        .serve_log_control(LogControl1::new(control))?
        .build()
        .await?;

    // Do other things or go to wait forever
    std::future::pending::<()>().await;

    Ok(())
}

Note that for systemctl to find the log control interface with systemctl service-log-level and systemctl service-log-target you need to make sure that

  • the interface is registered under logcontrol::DBUS_OBJ_PATH, and
  • the unit file provides the claimed bus name in the BusName attribute.

Otherwise systemd will not be able to change the log level or target.

Dependencies

~8–17MB
~266K SLoC