#systemd #log

logcontrol

Abstract types for the systemd logcontrol interface

2 stable releases

1.0.1 Sep 30, 2023

#520 in Debugging

Download history 22/week @ 2023-11-06 13/week @ 2023-11-13 66/week @ 2023-11-20 29/week @ 2023-11-27 10/week @ 2023-12-04 17/week @ 2023-12-11 17/week @ 2023-12-18 25/week @ 2023-12-25 16/week @ 2024-01-01 14/week @ 2024-01-08 42/week @ 2024-01-15 19/week @ 2024-01-22 16/week @ 2024-01-29 40/week @ 2024-02-05 56/week @ 2024-02-12 63/week @ 2024-02-19

181 downloads per month
Used in 3 crates

MIT/Apache

19KB
136 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-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 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_at(
            logcontrol::DBUS_OBJ_PATH,
            logcontrol_zbus::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");
    }
}

See tracing-server.rs for a more complete example.

Dependencies

~0.3–0.8MB
~19K SLoC