Rust types and implementations for systemd's logcontrol interface. https://crates.io/crates/logcontrol
Find a file
2025-05-05 21:53:35 +02:00
log Release logcontrol-log 0.1.2 2025-05-05 21:53:35 +02:00
log-reload Release log-reload 0.1.3 2025-05-05 21:53:35 +02:00
logcontrol Release logcontrol 1.0.3 2025-05-05 21:53:34 +02:00
tracing Release logcontrol-tracing 0.2.2 2025-05-05 21:53:34 +02:00
zbus Release logcontrol-zbus 3.0.2 2025-05-05 21:53:35 +02:00
.gitignore Initial commit 2023-09-28 08:28:32 +02:00
Cargo.lock Release logcontrol-log 0.1.2 2025-05-05 21:53:35 +02:00
Cargo.toml Replace github workflows 2025-05-05 21:43:26 +02:00
deny.toml Update allowlisted duplicates in tree 2025-03-25 20:26:47 +01:00
justfile Replace github workflows 2025-05-05 21:43:26 +02:00
LICENSE-Apache-2.0 Initial commit 2023-09-28 08:28:32 +02:00
LICENSE-MIT Initial commit 2023-09-28 08:28:32 +02:00
README.md Update URLs for codeberg.org 2025-05-05 21:42:39 +02:00

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");
    }
}