Crate logcontrol_tracing

Source
Expand description

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`.

Re-exports§

pub use logcontrol;

Structs§

PrettyLogControl1LayerFactory
A layer factory which uses pretty printing on stdout for the console target.
TracingLogControl1
A LogControl1 implementation for tracing.

Traits§

LogControl1LayerFactory
A factory to create layers for TracingLogControl1.

Functions§

from_log_level
Convert logcontrol::LogLevel to tracing::Level.
stderr_connected_to_journal
Whether the current process is directly connected to the systemd journal.
syslog_identifier
Determine the syslog identifier for this process.

Type Aliases§

LogControl1Layer
The final type for the layer that implements the log control interface.
LogTargetLayer
The type of the layer that implements the log target.