use anyhow::{Context, Result}; use colored::*; pub fn ejecutar(archivo: &str, nivel: &str, quiet: bool) -> Result<()> { let contenido = std::fs::read_to_string(archivo).with_context(|| format!("No se pudo leer '{}'", archivo))?; let nivel_upper = nivel.to_uppercase(); let mut encontradas = 0; for linea in contenido.lines() { if linea.to_uppercase().contains(&nivel_upper) { if quiet { println!("{}", linea); } else { let nivel_tag = match nivel_upper.as_str() { "ERROR" => "ERROR".red().bold(), "WARN" => "WARN".yellow().bold(), "INFO" => "INFO".green(), "DEBUG" => "DEBUG".cyan(), _ => nivel.normal(), }; println!("[{}] {}", nivel_tag, linea); encontradas += 1; } } } if !quiet { println!( "\n{} lineas encontradas con nivel '{}' en {}", encontradas.to_string().yellow(), nivel, archivo ); } Ok(()) }