linenumber

This commit is contained in:
Robin Appelman 2025-03-25 22:56:43 +01:00
commit f7ed810253
6 changed files with 23 additions and 17 deletions

7
Cargo.lock generated
View file

@ -485,6 +485,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
@ -1520,6 +1521,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "utf8parse"
version = "0.2.2"

View file

@ -20,7 +20,7 @@ time = { version = "0.3.37", features = ["serde", "serde-well-known", "parsing",
hdrhistogram = "7.5.4"
ahash = "0.8.11"
base64 = "0.22.1"
derive_more = { version = "2.0.1", features = ["from"] }
derive_more = { version = "2.0.1", features = ["from", "display"] }
rayon = "1.10.0"
tar = "0.4.43"
zip = "2.2.2"

View file

@ -1,6 +1,7 @@
use crate::app::Filter;
use crate::logfile::LogIndex;
use ahash::AHasher;
use derive_more::{Display, From};
use logsmash_data::LogLevel;
use serde::Deserialize;
use serde_json::Value;
@ -164,13 +165,18 @@ impl<'a> LogLine<'a> {
}
}
#[derive(
Default, Deserialize, Debug, Copy, Clone, Hash, Display, From, PartialEq, Eq, Ord, PartialOrd,
)]
pub struct LineNumber(usize);
#[derive(Deserialize, Debug, Hash, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Exception<'a> {
pub message: Cow<'a, str>,
pub exception: Cow<'a, str>,
pub file: Cow<'a, str>,
pub line: usize,
pub line: LineNumber,
}
#[derive(Deserialize, Clone)]
@ -203,7 +209,7 @@ pub struct FullException {
pub code: ExceptionCode,
pub trace: Vec<Trace>,
pub file: String,
pub line: usize,
pub line: LineNumber,
pub previous: Option<Box<FullException>>,
}
@ -228,13 +234,10 @@ impl FullException {
pub struct Trace {
#[serde(default)]
pub file: String,
#[serde(default)]
pub line: usize,
#[serde(default)]
pub line: LineNumber,
pub function: String,
#[serde(default)]
pub class: String,
#[serde(default, rename = "type")]
#[serde(rename = "type")]
pub ty: Option<TinyAsciiStr<4>>,
#[serde(default)]
pub args: Vec<Value>,

View file

@ -6,7 +6,7 @@ use crate::logfile::archive::{Archive, ArchiveEntry, TarArchive, ZipArchive};
use bzip2_rs::DecoderReader;
use dialoguer::Select;
use flate2::read::GzDecoder;
pub use logline::LogLine;
pub use logline::{LineNumber, LogLine};
use ruzstd::decoding::StreamingDecoder;
use serde::Deserialize;
use std::io::{Cursor, Read, Seek};

View file

@ -1,4 +1,5 @@
use crate::logfile::logline::{Exception, LogLine};
use crate::logfile::LineNumber;
use itertools::Either;
use logsmash_data::{LogLevel, LoggingStatement, StatementList};
use std::hash::{Hash, Hasher};
@ -11,7 +12,7 @@ pub struct LogMatch {
pattern: &'static str,
exception: Option<&'static str>,
path: &'static str,
line: usize,
line: LineNumber,
index: usize,
}
@ -26,7 +27,7 @@ impl LogMatch {
},
exception: statement.exception,
path: statement.path,
line: statement.line,
line: statement.line.into(),
index,
}
}

View file

@ -142,12 +142,7 @@ fn trace_line(trace: &Trace, path_prefix_length: usize) -> Row {
.get(path_prefix_length..)
.unwrap_or_default(),
),
Text::from(if trace.line > 0 {
trace.line.to_string()
} else {
String::new()
})
.alignment(Alignment::Right),
Text::from(trace.line.to_string()).alignment(Alignment::Right),
Text::from(trace.function().to_string()),
])
}