Skip to main content

binocular/preview/structured_log/
format.rs

1use crate::preview::structured_log::types::{ColumnConfig, LogEntry};
2
3pub fn format_entry_visible(entry: &LogEntry, visible_cols: &[ColumnConfig]) -> String {
4    visible_cols
5        .iter()
6        .filter_map(|col| {
7            entry
8                .fields
9                .iter()
10                .find(|(k, _)| k == &col.field)
11                .map(|(k, v)| {
12                    if v.contains(' ') || v.contains('"') || v.is_empty() {
13                        format!("{}=\"{}\"", k, v.replace('"', "\\\""))
14                    } else {
15                        format!("{}={}", k, v)
16                    }
17                })
18        })
19        .collect::<Vec<_>>()
20        .join("  ")
21}