pub fn truncate_log(s: &str, max_chars: usize) -> String {
if s.chars().count() <= max_chars {
return s.to_string();
}
let byte_pos = s
.char_indices()
.nth(max_chars)
.map(|(pos, _)| pos)
.unwrap_or(s.len());
format!("{}...[truncated]", &s[..byte_pos])
}