4 stable releases

new 1.0.3 May 5, 2025
1.0.2 Feb 3, 2025
1.0.1 Sep 30, 2023

#333 in Debugging

Download history 37/week @ 2025-01-15 64/week @ 2025-01-22 175/week @ 2025-01-29 111/week @ 2025-02-05 44/week @ 2025-02-12 34/week @ 2025-02-19 26/week @ 2025-02-26 16/week @ 2025-03-05 34/week @ 2025-03-12 7/week @ 2025-03-19 8/week @ 2025-03-26 3/week @ 2025-04-02 21/week @ 2025-04-09 4/week @ 2025-04-16 112/week @ 2025-04-30

138 downloads per month
Used in 3 crates

MIT/Apache

20KB
177 lines

logcontrol.rs

Crates.io docs.rs

Types and implementations for systemd's logcontrol interface.

This interface provides means to change logging behaviour of system services at runtime, over D-Bus, or via systemctl service-log-level or systemctl service-log-target.

This repository provides a collection of traits of basic types and implementations of this interface:

  • logcontrol contains the basic types and defines an abstract trait for the interface.
  • logcontrol-tracing provides a logcontrol backend implementation for the tracing library.
  • logcontrol-log provides a logcontrol backend implementation for the log library.
  • logcontrol-zbus provides a DBus interface implementation for zbus DBus framework.

Usage

$ cargo add logcontrol-tracing
$ cargo add logcontrol-zbus
use std::error::Error;
use std::time::Duration;

use logcontrol_tracing::{PrettyLogControl1LayerFactory, TracingLogControl1};
use logcontrol_zbus::{ConnectionBuilderExt, LogControl1};
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>> {
    let (control, control_layer) =
        TracingLogControl1::new_auto(PrettyLogControl1LayerFactory, Level::INFO)?;
    let subscriber = Registry::default().with(control_layer);
    tracing::subscriber::set_global_default(subscriber).unwrap();
    let _conn = ConnectionBuilder::session()?
        .name("com.example.Foo")?
        .serve_log_control(LogControl1::new(control))?
        .build()
        .await?;

    loop {
        async_std::task::sleep(Duration::from_secs(5)).await;
        event!(Level::INFO, "An message at info level");
        async_std::task::sleep(Duration::from_secs(1)).await;
        event!(Level::WARN, "An message at warning level");
    }
}

No runtime deps