log index type

This commit is contained in:
Robin Appelman 2025-03-15 22:43:33 +01:00
commit efcb86d2cf
8 changed files with 33 additions and 16 deletions

View file

@ -1,5 +1,4 @@
use crate::logfile::LogFile;
use crate::logline::LogLine;
use crate::logfile::{LogFile, LogIndex, LogLine};
use crate::matcher::MatchResult;
use crate::timegraph::TimeGraph;
use logsmash_data::{LoggingStatementWithPathPrefix, StatementList};
@ -28,7 +27,7 @@ impl<'a> App<'a> {
self.matches.len() + 1 + unmatched_line_count
}
pub fn get_line(&self, index: usize) -> Option<&'a str> {
pub fn get_line(&self, index: LogIndex) -> Option<&'a str> {
self.log_file.nth(index)
}

View file

@ -1,4 +1,5 @@
use crate::app::Filter;
use crate::logfile::LogIndex;
use ahash::AHasher;
use logsmash_data::LogLevel;
use serde::Deserialize;
@ -25,7 +26,7 @@ pub static CUSTOM_TIME_FORMAT: OnceLock<Option<OwnedFormatItem>> = OnceLock::new
#[derive(Deserialize, Clone)]
pub struct LogLine<'a> {
#[serde(default)]
pub index: usize,
pub index: LogIndex,
#[serde(rename = "reqId")]
pub request_id: TinyAsciiStr<32>,
pub user: TinyAsciiStr<64>,
@ -43,7 +44,7 @@ pub struct LogLine<'a> {
}
mod date {
use crate::logline::CUSTOM_TIME_FORMAT;
use crate::logfile::logline::CUSTOM_TIME_FORMAT;
use serde::de::Error;
use serde::{Deserialize, Deserializer};
use time::format_description::well_known::Iso8601;

View file

@ -1,14 +1,32 @@
mod archive;
pub mod logline;
use crate::error::ReadError;
use crate::logfile::archive::{Archive, ArchiveEntry, TarArchive, ZipArchive};
use bzip2_rs::DecoderReader;
use dialoguer::Select;
use flate2::read::GzDecoder;
pub use logline::LogLine;
use ruzstd::decoding::StreamingDecoder;
use serde::Deserialize;
use std::io::{Cursor, Read, Seek};
use xz2::read::XzDecoder;
#[derive(Debug, Deserialize, Default, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct LogIndex(usize);
impl From<usize> for LogIndex {
fn from(index: usize) -> Self {
Self(index)
}
}
impl From<&usize> for LogIndex {
fn from(index: &usize) -> Self {
Self(*index)
}
}
pub struct LogFile {
content: String,
}
@ -53,8 +71,8 @@ impl LogFile {
self.content.lines()
}
pub fn nth(&self, index: usize) -> Option<&str> {
self.iter().nth(index)
pub fn nth(&self, index: LogIndex) -> Option<&str> {
self.iter().nth(index.0)
}
}

View file

@ -1,12 +1,12 @@
use crate::app::{App, LogMatch};
use crate::error::LogError;
use crate::logfile::LogFile;
use crate::logline::{Exception, FullException, FullLogLine, LogLine, CUSTOM_TIME_FORMAT};
use crate::matcher::{MatchResult, Matcher};
use crate::ui::run_ui;
use base64::prelude::*;
use clap::Parser;
use indicatif::{ParallelProgressIterator, ProgressStyle};
use logfile::logline::{Exception, FullException, FullLogLine, LogLine, CUSTOM_TIME_FORMAT};
use logsmash_data::{default_apps, get_statements, SourceDefinition};
use main_error::MainResult;
use rayon::prelude::*;
@ -19,7 +19,6 @@ use std::iter::once;
mod app;
mod error;
mod logfile;
mod logline;
mod matcher;
mod timegraph;
mod ui;
@ -99,7 +98,7 @@ fn main() -> MainResult {
.map(|(index, line)| {
let mut parsed = parse_line(line);
if let Ok(parsed) = parsed.as_mut() {
parsed.index = index;
parsed.index = index.into();
};
parsed.map_err(|err| (index, line, err))
})
@ -114,7 +113,7 @@ fn main() -> MainResult {
results.sort_by_key(|res| match res {
Ok((line, _)) => line.index,
Err((index, _, _)) => *index,
Err((index, _, _)) => index.into(),
});
let mut error_lines = Vec::with_capacity(32);

View file

@ -1,4 +1,4 @@
use crate::logline::{Exception, LogLine};
use crate::logfile::logline::{Exception, LogLine};
use itertools::Either;
use logsmash_data::{LogLevel, LoggingStatement, StatementList};
use std::hash::{Hash, Hasher};
@ -263,7 +263,7 @@ impl<'a> SingleMatchState<'a> {
#[test]
fn test_matcher() {
use crate::logline::Exception;
use crate::logfile::logline::Exception;
use std::str::FromStr;
use time::OffsetDateTime;
use tinystr::TinyAsciiStr;

View file

@ -1,5 +1,5 @@
use crate::app::{App, Filter};
use crate::logline::{format_time, LogLine};
use crate::logfile::logline::{format_time, LogLine};
use crate::ui::state::GroupedLogGrouping;
use crate::ui::style::TABLE_HEADER_STYLE;
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};

View file

@ -1,4 +1,4 @@
use crate::logline::{format_time, FullException, FullLogLine, Trace};
use crate::logfile::logline::{format_time, FullException, FullLogLine, Trace};
use crate::ui::style::TABLE_HEADER_STYLE;
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
use ratatui::prelude::*;

View file

@ -1,5 +1,5 @@
use crate::app::{App, Filter, LogMatch, EMPTY_FILTER};
use crate::logline::{FullLogLine, LogLine};
use crate::logfile::logline::{FullLogLine, LogLine};
use crate::ui::footer::FooterParams;
use crate::ui::input::{PopMode, UiEvent};
use crate::ui::table::ScrollbarTableState;