support reading logs from csv files
All checks were successful
CI / build (push) Successful in 24s
CI / checks (push) Successful in 27s
CI / build-nixpkgs (push) Successful in 16s

This commit is contained in:
Robin Appelman 2025-06-03 15:57:07 +02:00
commit e2474640d6
3 changed files with 41 additions and 3 deletions

View file

@ -4,12 +4,13 @@ pub mod logline;
use crate::error::ReadError;
use crate::logfile::archive::{Archive, ArchiveEntry, SevenZipArchive, TarArchive, ZipArchive};
use bzip2_rs::DecoderReader;
use csv::Reader;
use dialoguer::Select;
use flate2::read::GzDecoder;
pub use logline::{LineNumber, LogLine};
use ruzstd::decoding::StreamingDecoder;
use serde::Deserialize;
use std::io::{Cursor, Read, Seek};
use std::io::{BufReader, Cursor, Read, Seek};
use xz2::read::XzDecoder;
#[derive(Debug, Deserialize, Default, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
@ -55,7 +56,21 @@ impl LogFile {
return Self::open_no_seek(path, decoder);
}
Self::open_no_seek(path, Box::new(file))
if path.ends_with(".csv") {
let mut reader = Reader::from_reader(BufReader::new(file));
let mut content = String::with_capacity(8192);
for result in reader.records().filter_map(Result::ok) {
for field in result.iter() {
if field.starts_with('{') && field.ends_with('}') && field.contains("reqId") {
content.push_str(field);
content.push('\n');
}
}
}
Ok(LogFile { content })
} else {
Self::open_no_seek(path, Box::new(file))
}
}
fn open_no_seek<R: Read>(path: &str, mut file: R) -> Result<LogFile, ReadError> {