virtuoso_cli/
command_log.rs1use std::fs::{self, OpenOptions};
2use std::io::Write;
3use std::path::PathBuf;
4
5pub fn log_path() -> PathBuf {
6 let dir = dirs::cache_dir()
7 .unwrap_or_else(|| PathBuf::from("/tmp"))
8 .join("virtuoso_bridge")
9 .join("logs");
10 let _ = fs::create_dir_all(&dir);
11 dir.join("commands.log")
12}
13
14pub fn log_command(kind: &str, command: &str, duration_ms: Option<u128>) {
15 let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%.3f");
16 let dur = duration_ms.map(|d| format!(" ({d}ms)")).unwrap_or_default();
17 let line = format!("[{ts}] [{kind}]{dur} {command}\n");
18 if let Ok(mut f) = OpenOptions::new()
19 .create(true)
20 .append(true)
21 .open(log_path())
22 {
23 let _ = f.write_all(line.as_bytes());
24 }
25}