mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +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::borrow::Cow;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::iter::once;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
use time::format_description::well_known::iso8601::{Config, EncodedConfig, TimePrecision};
|
use time::format_description::well_known::iso8601::{Config, EncodedConfig, TimePrecision};
|
||||||
use time::format_description::well_known::Iso8601;
|
use time::format_description::well_known::Iso8601;
|
||||||
|
|
@ -184,7 +185,7 @@ impl<'a> LogLine<'a> {
|
||||||
},
|
},
|
||||||
exception.exception,
|
exception.exception,
|
||||||
exception.message,
|
exception.message,
|
||||||
exception.file,
|
exception.file(),
|
||||||
exception.line
|
exception.line
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -248,6 +249,13 @@ pub struct Exception<'a> {
|
||||||
pub line: LineNumber,
|
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)]
|
#[derive(Deserialize, Clone)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct FullLogLine {
|
pub struct FullLogLine {
|
||||||
|
|
@ -332,6 +340,31 @@ impl FullException {
|
||||||
exception: Some(self),
|
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)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ impl<'a> SingleLog<'a> {
|
||||||
let path_prefix_length = line
|
let path_prefix_length = line
|
||||||
.exception
|
.exception
|
||||||
.as_ref()
|
.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();
|
.unwrap_or_default();
|
||||||
let data_length = line.data().count();
|
let data_length = line.data().count();
|
||||||
SingleLog {
|
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) {
|
pub fn render_data(log: &FullLogLine) -> (ScrollbarTable, u16) {
|
||||||
let header = [Text::from("Key"), Text::from("Value")]
|
let header = [Text::from("Key"), Text::from("Value")]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue