Skip to main content

rskit_logging/
lib.rs

1//! Structured logging setup using the [`tracing`](https://docs.rs/tracing) ecosystem.
2//!
3//! # Layers
4//!
5//! - **Vocabulary (always available)** —
6//!   [`config::LoggingConfig`] / [`config::LogFormat`] / [`config::LogOutput`] describe logging declaratively
7//!   and carry no `tracing` dependency,
8//!   so configuration crates can compose them without linking the subscriber stack.
9//! - **Setup (`setup` feature, default-on)** — `init_logging` and friends, the `LoggingGuard`, masking,
10//!   sampling, per-module levels, and context helpers.
11//!   Everything built on `tracing`/`tracing-subscriber` lives here.
12//!
13//! # Usage
14//!
15//! ```ignore
16//! use rskit_logging::init_logging;
17//!
18//! let _guard = init_logging(&config.service.logging)?;
19//! // _guard must stay alive for the duration of the program
20//! tracing::info!(service = "my-svc", "started");
21//! ```
22//!
23//! # Design
24//!
25//! There is intentionally no global logger registry (unlike gokit's `logger.Get(name)`).
26//! Callers use `tracing` directly and scope context via spans + `#[tracing::instrument]`.
27//! `init_logging` installs a scoped default subscriber;
28//! the returned guard restores the previous subscriber on drop.
29
30#![warn(missing_docs)]
31
32/// Logging configuration vocabulary (tracing-free, always available).
33pub mod config;
34/// Error helpers for logging setup.
35pub mod error;
36/// Standard field name constants for the unified log schema.
37pub mod fields;
38
39/// Span-level context helpers — component tagging, request enrichment.
40#[cfg(feature = "setup")]
41pub mod context;
42/// Sensitive data masking for log output.
43#[cfg(feature = "setup")]
44pub mod masking;
45/// Per-module log level overrides from config.
46#[cfg(feature = "setup")]
47pub mod module_levels;
48/// OpenTelemetry Logs bridge with OTLP export.
49#[cfg(feature = "otlp")]
50pub mod otlp;
51/// Rate-based log sampling layer.
52#[cfg(feature = "setup")]
53pub mod sampling;
54/// Subscriber setup — building and installing `tracing` subscribers.
55#[cfg(feature = "setup")]
56pub mod setup;
57
58pub use config::{LogFormat, LogOutput, LoggingConfig};
59pub use error::LoggingResult;
60
61#[cfg(feature = "setup")]
62pub use masking::{DefaultMasker, Masker, MaskingConfig, MaskingMakeWriter};
63#[cfg(feature = "setup")]
64pub use module_levels::{ModuleLevelsConfig, build_env_filter};
65#[cfg(feature = "otlp")]
66pub use otlp::{OtlpConfig, OtlpProvider};
67#[cfg(feature = "setup")]
68pub use sampling::SamplingConfig;
69#[cfg(feature = "setup")]
70pub use setup::{
71    LoggingGuard, init_logging, init_logging_env, init_logging_with_masking,
72    init_logging_with_options,
73};
74#[cfg(feature = "otlp")]
75pub use setup::{LoggingSetup, init_logging_full};
76
77// Logging macros exposed by this crate.
78#[cfg(feature = "setup")]
79pub use tracing::{debug, error, info, instrument, trace, warn};