use super::types::LogLevel;
#[derive(Clone, Debug)]
pub struct LogEntry {
pub raw: String,
pub message: String,
pub level: LogLevel,
pub timestamp: Option<String>,
pub timestamp_value: Option<i64>,
pub source: Option<String>,
pub line_number: usize,
pub bookmarked: bool,
pub json_fields: Option<Vec<(String, String)>>,
pub expanded: bool,
}
impl LogEntry {
pub fn new(raw: impl Into<String>, line_number: usize) -> Self {
let raw = raw.into();
Self {
message: raw.clone(),
raw,
level: LogLevel::Info,
timestamp: None,
timestamp_value: None,
source: None,
line_number,
bookmarked: false,
json_fields: None,
expanded: false,
}
}
pub fn level(mut self, level: LogLevel) -> Self {
self.level = level;
self
}
pub fn message(mut self, msg: impl Into<String>) -> Self {
self.message = msg.into();
self
}
pub fn timestamp(mut self, ts: impl Into<String>) -> Self {
self.timestamp = Some(ts.into());
self
}
pub fn timestamp_value(mut self, value: i64) -> Self {
self.timestamp_value = Some(value);
self
}
pub fn source(mut self, src: impl Into<String>) -> Self {
self.source = Some(src.into());
self
}
pub fn json_fields(mut self, fields: Vec<(String, String)>) -> Self {
self.json_fields = Some(fields);
self
}
pub fn toggle_bookmark(&mut self) {
self.bookmarked = !self.bookmarked;
}
pub fn toggle_expanded(&mut self) {
self.expanded = !self.expanded;
}
}
#[derive(Clone, Debug)]
pub struct SearchMatch {
pub entry_index: usize,
pub start: usize,
pub end: usize,
}