mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
support reading logs from csv files
This commit is contained in:
parent
758a4fa5e3
commit
e2474640d6
3 changed files with 41 additions and 3 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue