Crate log_args_runtime

Crate log_args_runtime 

Source
Expand description

log-args-runtime

Runtime support for the log_args procedural macros. This crate provides:

  • Context storage and helpers to push/pop context across sync and async boundaries
  • Logging macros (info!, warn!, error!, debug!, trace!) that automatically merge inherited context into your events
  • log_with_context! which enriches an underlying tracing macro

Feature flags

  • with_context (off by default): When enabled, the runtime includes a context field (debug-formatted map) in each log when there is context available. Configure your tracing-subscriber JSON formatter with .flatten_event(true) to surface the fields at the top level in JSON output.

Quick start

use tracing::{info, Level};

fn init() {
    tracing_subscriber::fmt().json().flatten_event(true).with_max_level(Level::DEBUG).init();
}

fn main() {
    init();
    log_args_runtime::info!("hello");
}

Macros§

debug
error
info
Global context-aware logging macros that inherit parent context These can be used in any function to automatically include context from parent functions with span
log_with_context
trace
warn

Structs§

AsyncContextGuard
Guard for async context that automatically pops on drop

Constants§

WITH_CONTEXT_ENABLED

Functions§

auto_capture_context
Automatically capture and preserve current context for function execution This ensures context is maintained across function boundaries without user intervention
capture_context
Capture current context and store it globally for cross-boundary persistence This function is automatically called by the macro to ensure context is preserved
get_context_value
get_global_context
Get global context for cross-boundary persistence
get_inherited_context_string
Get inherited context as a formatted string for automatic span propagation This function retrieves all context fields from the current span context and formats them as a string for logging
get_inherited_fields_map
Get inherited context fields as individual key-value pairs This function returns a HashMap of inherited context fields for dynamic field injection
set_global_context
Set global context that persists across all boundaries