mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
clean paths in LogLine::display
This commit is contained in:
parent
9724fb31a5
commit
600e51ccf4
2 changed files with 35 additions and 23 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue