A cross-platform tracing layer for native
operating-system logging.
OsLogLayer selects a backend at compile time:
- macOS uses Apple Unified Logging (
os_log) and Activity Tracing (os_activity). Activity scopes are entered and left insideon_event, so they never span asynchronous task migration between threads. - Linux uses
tracing-journaldand returnsNonewhen the systemd journal socket is unavailable. - Windows uses the Windows Event Log Application log through
the
eventlogcrate's native backend and embedded message resources. Thesubsystemmust already be registered as an event source, normally by an installer, with the application executable as its message file;try_newreturnsNonewhen Windows cannot open it. Thecategoryis included in each event message. - Other platforms expose the same API as a no-op layer and return
None.
use tracing_subscriber::prelude::*;
use tracing_os_layer::OsLogLayer;
let native = OsLogLayer::try_new("com.example.app", "worker");
tracing_subscriber::registry()
.with(native)
.init();
tracing::info!(records = 12, "processed input");The returned Option can be passed directly to a subscriber because
Option<L> implements Layer<S>: unavailable native logging is simply left
out of the subscriber stack.
This crate only adapts tracing events and spans to native OS logging. It does
not configure global subscribers, choose application identifiers, or impose a
logging policy.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.