Module logger

Module logger 

Source
Expand description

Logging system for CLI operations.

This module provides structured logging using the tracing library, with strict separation between logs (stderr) and output (stdout).

§What

Provides:

  • Logging initialization based on LogLevel
  • Tracing subscriber configuration
  • Convenience macros for logging at different levels
  • RUST_LOG environment variable support
  • Proper stream separation (stderr for logs, stdout for output)

§How

Uses tracing and tracing-subscriber to create a global logging system that writes exclusively to stderr. The logging level is controlled by the --log-level CLI flag, which is completely independent of the --format flag that controls stdout output.

§Why

Separating logs (stderr) from output (stdout) enables:

  • Clean JSON output that’s never mixed with logs
  • Reliable piping and parsing in automation
  • Debugging without contaminating command output
  • Independent control of verbosity and format

§Examples

use sublime_cli_tools::output::logger::init_logging;
use sublime_cli_tools::cli::LogLevel;

// Initialize logging at startup
init_logging(LogLevel::Info, false)?;

// Use logging macros in your code
tracing::info!("Operation started");
tracing::debug!("Processing item: {}", "example");
tracing::warn!("Potential issue detected");

Macros§

debug
Re-exports for convenience.
error
Re-exports for convenience.
info
Re-exports for convenience.
trace
Re-exports for convenience.
warn
Re-exports for convenience.

Functions§

command_span
Creates a tracing span for command execution.
init_logging
Initializes the global tracing subscriber for logging.
operation_span
Creates a tracing span for a specific operation.