Logging Macros

Overview

Unified tracing macros that work with or without the tracing feature.

Available Macros

trace_debug!(...)   // Debug-level messages
trace_info!(...)    // Informational messages
trace_warn!(...)    // Warning messages
trace_error!(...)   // Error messages

Usage

Basic Logging

use lighty_core::{trace_info, trace_error};

fn process_file(path: &str)  {
    trace_info!("Processing file: {}", path);

    match std::fs::read(path) {
        Ok(data) => {
            trace_info!("File read successfully: {} bytes", data.len());
            Ok(())
        }
        Err(e) => {
            trace_error!("Failed to read file: {}", e);
            Err(e.into())
        }
    }
}

Structured Logging (with tracing feature)

Feature Flags

With tracing Feature

Macros expand to tracing::*! calls with full structured logging support.

Without tracing Feature

Macros expand to no-ops (zero runtime cost).

Best Practices

1. Use Appropriate Levels

2. Include Context

3. Don't Log Sensitive Data

See Also

Last updated