1#[cfg(feature = "logging")]
6use log::{debug, error, info, warn};
7
8#[cfg(feature = "logging")]
10pub fn log_command(program: &str, args: &[std::ffi::OsString]) {
11 let args_str: Vec<String> = args
12 .iter()
13 .map(|s| s.to_string_lossy().to_string())
14 .collect();
15
16 debug!("Executing command: {} {:?}", program, args_str);
17}
18
19#[cfg(feature = "logging")]
21pub fn log_success(program: &str, exit_code: Option<i32>) {
22 info!(
23 "Command '{}' completed with exit code: {:?}",
24 program, exit_code
25 );
26}
27
28#[cfg(feature = "logging")]
30pub fn log_failure(program: &str, exit_code: Option<i32>, stderr: &str) {
31 error!(
32 "Command '{}' failed with exit code: {:?}, stderr: {}",
33 program, exit_code, stderr
34 );
35}
36
37#[cfg(feature = "logging")]
39pub fn log_timeout(program: &str, duration: std::time::Duration) {
40 warn!("Command '{}' timed out after {:?}", program, duration);
41}
42
43#[cfg(feature = "logging")]
45pub fn log_env_set(key: &str, value: &str) {
46 debug!("Setting environment variable: {}={}", key, value);
47}
48
49#[cfg(feature = "logging")]
51pub fn log_cwd(path: &std::path::Path) {
52 debug!("Changing working directory to: {:?}", path);
53}
54
55#[cfg(not(feature = "logging"))]
57#[allow(missing_docs)]
58pub fn log_command(_program: &str, _args: &[std::ffi::OsString]) {}
59
60#[cfg(not(feature = "logging"))]
61#[allow(missing_docs)]
62pub fn log_success(_program: &str, _exit_code: Option<i32>) {}
63
64#[cfg(not(feature = "logging"))]
65#[allow(missing_docs)]
66pub fn log_failure(_program: &str, _exit_code: Option<i32>, _stderr: &str) {}
67
68#[cfg(not(feature = "logging"))]
69#[allow(missing_docs)]
70pub fn log_timeout(_program: &str, _duration: std::time::Duration) {}
71
72#[cfg(not(feature = "logging"))]
73#[allow(missing_docs)]
74pub fn log_env_set(_key: &str, _value: &str) {}
75
76#[cfg(not(feature = "logging"))]
77#[allow(missing_docs)]
78pub fn log_cwd(_path: &std::path::Path) {}