clean paths in LogLine::display
All checks were successful
CI / build (push) Successful in 42s
CI / checks (push) Successful in 49s
CI / build-nixpkgs (push) Successful in 35s

This commit is contained in:
Robin Appelman 2025-11-19 16:37:39 +01:00
commit 600e51ccf4
2 changed files with 35 additions and 23 deletions

View file

@ -9,6 +9,7 @@ use serde_json::Value;
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
use std::hash::{Hash, Hasher};
use std::iter::once;
use std::sync::OnceLock;
use time::format_description::well_known::iso8601::{Config, EncodedConfig, TimePrecision};
use time::format_description::well_known::Iso8601;
@ -184,7 +185,7 @@ impl<'a> LogLine<'a> {
},
exception.exception,
exception.message,
exception.file,
exception.file(),
exception.line
))
} else {
@ -248,6 +249,13 @@ pub struct Exception<'a> {
pub line: LineNumber,
}
impl Exception<'_> {
pub fn file(&self) -> &str {
let prefix_length = find_path_prefix_length(once(self.file.as_ref()));
&self.file[prefix_length..]
}
}
#[derive(Deserialize, Clone)]
#[allow(dead_code)]
pub struct FullLogLine {
@ -332,6 +340,31 @@ impl FullException {
exception: Some(self),
}
}
pub fn path_prefix_length(&self) -> usize {
find_path_prefix_length(self.trace.iter().map(|t| t.file.as_str()))
}
}
fn find_path_prefix_length<'a, I: Iterator<Item = &'a str>>(paths: I) -> usize {
let patterns = [
"/3rdparty/",
"/apps/",
"/lib/private",
"/remote.php",
"/public.php",
"/index.php",
];
for path in paths {
for pattern in patterns {
if let Some(offset) = path.find(pattern) {
if !path.contains("files_external/3rdparty") {
return offset + 1;
}
}
}
}
0
}
#[derive(Deserialize, Debug, Clone)]

View file

@ -21,7 +21,7 @@ impl<'a> SingleLog<'a> {
let path_prefix_length = line
.exception
.as_ref()
.map(|ex| find_path_prefix_length(ex.trace.iter().map(|t| t.file.as_str())))
.map(FullException::path_prefix_length)
.unwrap_or_default();
let data_length = line.data().count();
SingleLog {
@ -190,27 +190,6 @@ fn trace_line(trace: &Trace, path_prefix_length: usize) -> Row {
])
}
fn find_path_prefix_length<'a, I: Iterator<Item = &'a str>>(paths: I) -> usize {
let patterns = [
"/3rdparty/",
"/apps/",
"/lib/private",
"/remote.php",
"/public.php",
"/index.php",
];
for path in paths {
for pattern in patterns {
if let Some(offset) = path.find(pattern) {
if !path.contains("files_external/3rdparty") {
return offset + 1;
}
}
}
}
0
}
pub fn render_data(log: &FullLogLine) -> (ScrollbarTable, u16) {
let header = [Text::from("Key"), Text::from("Value")]
.into_iter()