tracing_systemd/lib.rs
1//! `tracing-subscriber` layer for logging to the systemd journal
2//!
3//! Provides a [`SystemdLayer`] implementation for use with `tracing-subscriber` that can be configured.
4//! Shows all spans and arguments.
5//!
6//! # Features
7//! - `colored` (default): Enables colored output
8//! - `sd-journal`: Enables logging to the systemd journal (useful for running outside of a service)
9//! - Requires `libsystemd-dev` to be installed
10//! - Filter using `-t` | `--identifier` (e.g. `journalctl -t <identifier>`)
11//!
12//! # Example
13//! ```rust
14//! use tracing::error;
15//!
16//! use tracing::{debug, info, instrument, trace, warn};
17//! use tracing_subscriber::prelude::*;
18//! use tracing_systemd::SystemdLayer;
19//! fn main() {
20//! tracing_subscriber::registry()
21//! .with(
22//! SystemdLayer::new()
23//! .with_target(true)
24//! .use_level_prefix(false)
25//! .use_color(true)
26//! .with_thread_ids(true),
27//! )
28//! .init();
29//!
30//! root_log_fn(true);
31//! }
32//!
33//! #[instrument(fields(outside_instrument_field = true))]
34//! fn root_log_fn(outside_instrument_field: bool) {
35//! info!("Root log");
36//! inner_log_1(true);
37//! }
38//!
39//! #[instrument(fields(inside_instrument_field = true))]
40//! fn inner_log_1(inside_parameter_field: bool) {
41//! trace!("this is a trace");
42//! debug!(field_in_function = "also works");
43//! info!("this is an info log");
44//! warn!("Inner log 1");
45//! error!("this is an error");
46//! }
47//! ```
48
49#![warn(missing_docs)]
50
51mod formatting;
52mod systemd_layer;
53
54pub use systemd_layer::SystemdLayer;
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn it_works() {
62 let result = 2 + 2;
63 assert_eq!(result, 4);
64 }
65}