(_level: Option<LogLevel>, log_dir: Option<PathBuf>, print: bool)
| 321 | } |
| 322 | |
| 323 | pub fn init(_level: Option<LogLevel>, log_dir: Option<PathBuf>, print: bool) -> Option<PathBuf> { |
| 324 | if print { |
| 325 | return None; |
| 326 | } |
| 327 | |
| 328 | let log_dir = log_dir.unwrap_or_else(|| PathBuf::from(".")); |
| 329 | let timestamp = Local::now().format("%Y-%m-%dT%H%M%S").to_string(); |
| 330 | let log_path = log_dir.join(format!("{}.log", timestamp)); |
| 331 | |
| 332 | if let Some(parent) = log_path.parent() { |
| 333 | let _ = std::fs::create_dir_all(parent); |
| 334 | } |
| 335 | |
| 336 | let file = std::fs::OpenOptions::new() |
| 337 | .create(true) |
| 338 | .write(true) |
| 339 | .truncate(true) |
| 340 | .open(&log_path) |
| 341 | .ok(); |
| 342 | |
| 343 | if let Some(file) = file { |
| 344 | let writer: Arc<Mutex<Box<dyn Write + Send>>> = Arc::new(Mutex::new(Box::new(file))); |
| 345 | if let Ok(mut loggers) = LOGGERS.lock() { |
| 346 | for (_, cached) in loggers.iter_mut() { |
| 347 | cached.writer = Arc::clone(&writer); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | Some(log_path) |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | pub fn init_tracing(_level: Option<&str>, log_dir: Option<PathBuf>, print: bool) -> Option<PathBuf> { |
no test coverage detected