Skip to main content

Crate tracing_os_layer

Crate tracing_os_layer 

Source
Expand description

§tracing-os-layer

Crates.io Documentation CI License

A cross-platform tracing layer for native operating-system logging.

§Backends

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 inside on_event, so they never span asynchronous task migration between threads.
  • Linux uses tracing-journald and returns None when the systemd journal socket is unavailable.
  • Windows uses the Windows Event Log Application log through the eventlog crate’s native backend and embedded message resources. The subsystem must already be registered as an event source, normally by an installer, with the application executable as its message file; try_new returns None when Windows cannot open it. The category is included in each event message.
  • Other platforms expose the same API as a no-op layer and return None.

§Example

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.

§Scope

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.

§License

Licensed under either of:

at your option.

§Platform dispatch

OsLogLayer is a different concrete type on each platform, selected at compile time. The public API is identical:

use tracing_os_layer::OsLogLayer;

let _layer = OsLogLayer::try_new("com.example.app", "worker");

Structs§

OsLogLayer
Layer that emits events to the systemd journal.