mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
log index type
This commit is contained in:
parent
7584aff9ea
commit
efcb86d2cf
8 changed files with 33 additions and 16 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::logfile::LogFile;
|
use crate::logfile::{LogFile, LogIndex, LogLine};
|
||||||
use crate::logline::LogLine;
|
|
||||||
use crate::matcher::MatchResult;
|
use crate::matcher::MatchResult;
|
||||||
use crate::timegraph::TimeGraph;
|
use crate::timegraph::TimeGraph;
|
||||||
use logsmash_data::{LoggingStatementWithPathPrefix, StatementList};
|
use logsmash_data::{LoggingStatementWithPathPrefix, StatementList};
|
||||||
|
|
@ -28,7 +27,7 @@ impl<'a> App<'a> {
|
||||||
self.matches.len() + 1 + unmatched_line_count
|
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)
|
self.log_file.nth(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::app::Filter;
|
use crate::app::Filter;
|
||||||
|
use crate::logfile::LogIndex;
|
||||||
use ahash::AHasher;
|
use ahash::AHasher;
|
||||||
use logsmash_data::LogLevel;
|
use logsmash_data::LogLevel;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -25,7 +26,7 @@ pub static CUSTOM_TIME_FORMAT: OnceLock<Option<OwnedFormatItem>> = OnceLock::new
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone)]
|
||||||
pub struct LogLine<'a> {
|
pub struct LogLine<'a> {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub index: usize,
|
pub index: LogIndex,
|
||||||
#[serde(rename = "reqId")]
|
#[serde(rename = "reqId")]
|
||||||
pub request_id: TinyAsciiStr<32>,
|
pub request_id: TinyAsciiStr<32>,
|
||||||
pub user: TinyAsciiStr<64>,
|
pub user: TinyAsciiStr<64>,
|
||||||
|
|
@ -43,7 +44,7 @@ pub struct LogLine<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod date {
|
mod date {
|
||||||
use crate::logline::CUSTOM_TIME_FORMAT;
|
use crate::logfile::logline::CUSTOM_TIME_FORMAT;
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
use time::format_description::well_known::Iso8601;
|
use time::format_description::well_known::Iso8601;
|
||||||
|
|
@ -1,14 +1,32 @@
|
||||||
mod archive;
|
mod archive;
|
||||||
|
pub mod logline;
|
||||||
|
|
||||||
use crate::error::ReadError;
|
use crate::error::ReadError;
|
||||||
use crate::logfile::archive::{Archive, ArchiveEntry, TarArchive, ZipArchive};
|
use crate::logfile::archive::{Archive, ArchiveEntry, TarArchive, ZipArchive};
|
||||||
use bzip2_rs::DecoderReader;
|
use bzip2_rs::DecoderReader;
|
||||||
use dialoguer::Select;
|
use dialoguer::Select;
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
|
pub use logline::LogLine;
|
||||||
use ruzstd::decoding::StreamingDecoder;
|
use ruzstd::decoding::StreamingDecoder;
|
||||||
|
use serde::Deserialize;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
use xz2::read::XzDecoder;
|
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 {
|
pub struct LogFile {
|
||||||
content: String,
|
content: String,
|
||||||
}
|
}
|
||||||
|
|
@ -53,8 +71,8 @@ impl LogFile {
|
||||||
self.content.lines()
|
self.content.lines()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nth(&self, index: usize) -> Option<&str> {
|
pub fn nth(&self, index: LogIndex) -> Option<&str> {
|
||||||
self.iter().nth(index)
|
self.iter().nth(index.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::app::{App, LogMatch};
|
use crate::app::{App, LogMatch};
|
||||||
use crate::error::LogError;
|
use crate::error::LogError;
|
||||||
use crate::logfile::LogFile;
|
use crate::logfile::LogFile;
|
||||||
use crate::logline::{Exception, FullException, FullLogLine, LogLine, CUSTOM_TIME_FORMAT};
|
|
||||||
use crate::matcher::{MatchResult, Matcher};
|
use crate::matcher::{MatchResult, Matcher};
|
||||||
use crate::ui::run_ui;
|
use crate::ui::run_ui;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use indicatif::{ParallelProgressIterator, ProgressStyle};
|
use indicatif::{ParallelProgressIterator, ProgressStyle};
|
||||||
|
use logfile::logline::{Exception, FullException, FullLogLine, LogLine, CUSTOM_TIME_FORMAT};
|
||||||
use logsmash_data::{default_apps, get_statements, SourceDefinition};
|
use logsmash_data::{default_apps, get_statements, SourceDefinition};
|
||||||
use main_error::MainResult;
|
use main_error::MainResult;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
@ -19,7 +19,6 @@ use std::iter::once;
|
||||||
mod app;
|
mod app;
|
||||||
mod error;
|
mod error;
|
||||||
mod logfile;
|
mod logfile;
|
||||||
mod logline;
|
|
||||||
mod matcher;
|
mod matcher;
|
||||||
mod timegraph;
|
mod timegraph;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
@ -99,7 +98,7 @@ fn main() -> MainResult {
|
||||||
.map(|(index, line)| {
|
.map(|(index, line)| {
|
||||||
let mut parsed = parse_line(line);
|
let mut parsed = parse_line(line);
|
||||||
if let Ok(parsed) = parsed.as_mut() {
|
if let Ok(parsed) = parsed.as_mut() {
|
||||||
parsed.index = index;
|
parsed.index = index.into();
|
||||||
};
|
};
|
||||||
parsed.map_err(|err| (index, line, err))
|
parsed.map_err(|err| (index, line, err))
|
||||||
})
|
})
|
||||||
|
|
@ -114,7 +113,7 @@ fn main() -> MainResult {
|
||||||
|
|
||||||
results.sort_by_key(|res| match res {
|
results.sort_by_key(|res| match res {
|
||||||
Ok((line, _)) => line.index,
|
Ok((line, _)) => line.index,
|
||||||
Err((index, _, _)) => *index,
|
Err((index, _, _)) => index.into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut error_lines = Vec::with_capacity(32);
|
let mut error_lines = Vec::with_capacity(32);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::logline::{Exception, LogLine};
|
use crate::logfile::logline::{Exception, LogLine};
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
use logsmash_data::{LogLevel, LoggingStatement, StatementList};
|
use logsmash_data::{LogLevel, LoggingStatement, StatementList};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
@ -263,7 +263,7 @@ impl<'a> SingleMatchState<'a> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_matcher() {
|
fn test_matcher() {
|
||||||
use crate::logline::Exception;
|
use crate::logfile::logline::Exception;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use tinystr::TinyAsciiStr;
|
use tinystr::TinyAsciiStr;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::app::{App, Filter};
|
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::state::GroupedLogGrouping;
|
||||||
use crate::ui::style::TABLE_HEADER_STYLE;
|
use crate::ui::style::TABLE_HEADER_STYLE;
|
||||||
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||||
|
|
|
||||||
|
|
@ -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::style::TABLE_HEADER_STYLE;
|
||||||
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||||
use ratatui::prelude::*;
|
use ratatui::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::app::{App, Filter, LogMatch, EMPTY_FILTER};
|
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::footer::FooterParams;
|
||||||
use crate::ui::input::{PopMode, UiEvent};
|
use crate::ui::input::{PopMode, UiEvent};
|
||||||
use crate::ui::table::ScrollbarTableState;
|
use crate::ui::table::ScrollbarTableState;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue