bare-script 0.1.1

The type-safe scripting authority for Rust. A framework for building robust shell commands and automation with 'Parse, don't validate' philosophy.
Documentation
//! Logging support for bare-script.
//!
//! This module provides logging functionality when the `logging` feature is enabled.

#[cfg(feature = "logging")]
use log::{debug, error, info, warn};

/// Logs command execution details.
#[cfg(feature = "logging")]
pub fn log_command(program: &str, args: &[std::ffi::OsString]) {
    let args_str: Vec<String> = args
        .iter()
        .map(|s| s.to_string_lossy().to_string())
        .collect();

    debug!("Executing command: {} {:?}", program, args_str);
}

/// Logs command success.
#[cfg(feature = "logging")]
pub fn log_success(program: &str, exit_code: Option<i32>) {
    info!(
        "Command '{}' completed with exit code: {:?}",
        program, exit_code
    );
}

/// Logs command failure.
#[cfg(feature = "logging")]
pub fn log_failure(program: &str, exit_code: Option<i32>, stderr: &str) {
    error!(
        "Command '{}' failed with exit code: {:?}, stderr: {}",
        program, exit_code, stderr
    );
}

/// Logs timeout.
#[cfg(feature = "logging")]
pub fn log_timeout(program: &str, duration: std::time::Duration) {
    warn!("Command '{}' timed out after {:?}", program, duration);
}

/// Logs environment variable changes.
#[cfg(feature = "logging")]
pub fn log_env_set(key: &str, value: &str) {
    debug!("Setting environment variable: {}={}", key, value);
}

/// Logs working directory change.
#[cfg(feature = "logging")]
pub fn log_cwd(path: &std::path::Path) {
    debug!("Changing working directory to: {:?}", path);
}

/// No-op implementations when logging is disabled.
#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_command(_program: &str, _args: &[std::ffi::OsString]) {}

#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_success(_program: &str, _exit_code: Option<i32>) {}

#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_failure(_program: &str, _exit_code: Option<i32>, _stderr: &str) {}

#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_timeout(_program: &str, _duration: std::time::Duration) {}

#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_env_set(_key: &str, _value: &str) {}

#[cfg(not(feature = "logging"))]
#[allow(missing_docs)]
pub fn log_cwd(_path: &std::path::Path) {}