better log message

This commit is contained in:
Robin Appelman 2024-07-26 22:44:59 +02:00
commit adb370e6bb
9 changed files with 62 additions and 19 deletions

View file

@ -25,14 +25,47 @@ impl LogLine {
.as_ref()
.map(|e| e.exception.as_str())
.hash(&mut hasher);
self.exception
.as_ref()
.map(|e| e.file.as_str())
.hash(&mut hasher);
self.app.hash(&mut hasher);
self.exception.as_ref().map(|e| e.line).hash(&mut hasher);
self.app.hash(&mut hasher);
hasher.finish()
}
}
impl LogLine {
pub fn display(&self) -> String {
if let Some(exception) = self.exception.as_ref() {
format!(
"{}{}{}({}) - {} line {}",
if self.message.starts_with("Exception thrown:") {
""
} else {
self.message.as_str()
},
if self.message.starts_with("Exception thrown:") {
""
} else {
": "
},
exception.exception,
exception.message,
exception.file,
exception.line
)
} else {
self.message.clone()
}
}
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Exception {
pub message: String,
pub exception: String,
pub file: String,
pub line: usize,

View file

@ -22,8 +22,6 @@ mod ui;
#[derive(Debug, Parser)]
struct Args {
file: String,
#[arg(long)]
unmatched: bool,
}
fn main() -> MainResult {
@ -72,15 +70,10 @@ fn main() -> MainResult {
};
if let Some(index) = matcher.match_log(&parsed) {
counts.entry(index).or_default().push(i);
} else if let Some(entry) = unmatched_counts.get_mut(parsed.app.as_str()) {
entry.push(i)
} else {
if args.unmatched && parsed.app != "PHP" {
println!("{} :{:?}", parsed.message, &parsed.exception);
}
if let Some(entry) = unmatched_counts.get_mut(parsed.app.as_str()) {
entry.push(i)
} else {
unmatched_lines.push(i);
}
unmatched_lines.push(i);
}
parsed_lines.push(parsed);
i += 1;

View file

@ -252,6 +252,7 @@ fn test_matcher() {
level: LogLevel::Error,
message: "Unsupported query value for mimetype: %/text, only values in the format \"mime/type\" or \"mime/%\" are supported".into(),
exception: Some(Exception {
message: "".into(),
exception: "Bar\\FooException".into(),
file: "short".into(),
line: 68,

View file

@ -37,7 +37,7 @@ fn log_row(line: &LogLine) -> Row<'static> {
Row::new([
Text::from(line.level.as_str().to_string()),
Text::from(line.app.to_string()),
Text::from(line.message.clone()),
Text::from(line.display()),
Text::from(line.time.format(&Iso8601::<TIME_FORMAT>).unwrap()).alignment(Alignment::Right),
])
}

View file

@ -40,7 +40,7 @@ fn group_row(app: &App, group: &GroupedLines) -> Row<'static> {
Row::new([
line.level.as_str().to_string(),
line.app.to_string(),
line.message.clone(),
line.display(),
sparkline(&group.histogram.counts(10)),
group.len().to_string(),
])

View file

@ -179,7 +179,11 @@ mod table_state {
fn up(&mut self, count: usize, step: usize) -> usize {
let current = self.selected().unwrap_or(0);
let after = if step > current {
count - 1
if step == 1 {
count - 1
} else {
0
}
} else {
current - step
};
@ -190,7 +194,11 @@ mod table_state {
fn down(&mut self, count: usize, step: usize) -> usize {
let current = self.selected().unwrap_or(0);
let after = if step >= count - current {
0
if step == 1 {
0
} else {
count - 1
}
} else {
current + step
};