#tracing #log #systemd #logging #back-end

logcontrol-tracing

Tracing backend for the log control interface

2 unstable releases

0.2.0 Sep 30, 2023
0.1.0 Sep 30, 2023

#770 in Debugging

39 downloads per month

MIT/Apache

37KB
362 lines

logcontrol-tracing

Crates.io docs.rs

tracing implementation for the logcontrol interface.

Usage

$ cargo add logcontrol-tracing
use logcontrol::*;
use logcontrol_tracing::*;
use tracing_subscriber::prelude::*;

let (control, layer) = TracingLogControl1::new_auto(
    PrettyLogControl1LayerFactory,
    tracing::Level::INFO,
).unwrap();

let subscriber = tracing_subscriber::Registry::default().with(layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
// Then register `control` over DBus, e.g. via `logcontrol_zbus::LogControl1`.

lib.rs:

A LogControl1 implementation for tracing.

TracingLogControl1 provides a LogControl1 implementation on top of tracing, which uses the reload layer to dyanmically switch layers and level filters when the log target or log level are changed over the log control interfaces.

It uses a LogControl1LayerFactory implementation to create the log target layers each time the log target is changed. This crates provides a default PrettyLogControl1LayerFactory which uses the pretty format of tracing_subscriber on stdout for the console target and tracing_journald for the Journal target. You can provide your own implementation to customize the layer for each target.

When created TracingLogControl1 additionally returns a layer which needs to be added to the global tracing subscriber, i.e. a tracing_subscriber::Registry, for log control to have any effect.

use logcontrol::*;
use logcontrol_tracing::*;
use tracing_subscriber::prelude::*;

let (control, layer) = TracingLogControl1::new_auto(
    PrettyLogControl1LayerFactory,
    tracing::Level::INFO,
).unwrap();

let subscriber = tracing_subscriber::Registry::default().with(layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
// Then register `control` over DBus, e.g. via `logcontrol_zbus::LogControl1`.

Dependencies

~4.5–6.5MB
~111K SLoC