cleanup
Some checks failed
CI / matrix (push) Failing after 2s
CI / ${{ matrix.check }} (push) Has been skipped
CI / build (push) Has been skipped
CI / build-nixpkgs (push) Has been skipped

This commit is contained in:
Robin Appelman 2024-09-27 18:17:54 +02:00
commit e17bbb4950
6 changed files with 60 additions and 69 deletions

View file

@ -4,11 +4,8 @@ use crate::matcher::MatchResult;
use crate::timegraph::TimeGraph;
use logsmash_data::StatementList;
use std::collections::BTreeMap;
use time::OffsetDateTime;
pub struct App<'a> {
pub first_date: OffsetDateTime,
pub last_date: OffsetDateTime,
pub lines: Vec<LogLine<'a>>,
pub log_statements: StatementList,
pub matches: Vec<LogMatch>,

View file

@ -137,6 +137,7 @@ pub struct Exception<'a> {
}
#[derive(Deserialize, Clone)]
#[allow(dead_code)]
pub struct FullLogLine {
#[serde(rename = "reqId")]
pub request_id: TinyAsciiStr<32>,
@ -158,6 +159,7 @@ pub struct FullLogLine {
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
#[allow(dead_code)]
pub struct FullException {
pub exception: String,
pub message: String,
@ -170,6 +172,7 @@ pub struct FullException {
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
#[allow(dead_code)]
pub enum ExceptionCode {
Num(isize),
String(String),
@ -184,6 +187,7 @@ impl FullException {
}
#[derive(Deserialize, Debug, Clone)]
#[allow(dead_code)]
pub struct Trace {
#[serde(default)]
pub file: String,

View file

@ -130,8 +130,6 @@ fn main() -> MainResult {
.collect();
let app = App {
first_date: parsed_lines[0].time,
last_date: parsed_lines.last().unwrap().time,
lines: parsed_lines,
log_statements: statements,
error_lines,

View file

@ -184,10 +184,12 @@ fn ui(frame: &mut Frame, app: &App, state: &mut UiState) {
frame.render_widget(footer(app, page), layout[2]);
}
UiState::Log(LogState {
log, table_state, ..
table_state,
full_line,
..
}) => {
frame.render_stateful_widget(
single_log(app, log),
single_log(full_line),
layout[0].union(layout[1]),
table_state,
);

View file

@ -1,28 +1,24 @@
use crate::app::App;
use crate::logline::{format_time, FullException, FullLogLine, LogLine, Trace};
use crate::parse_line_full;
use crate::logline::{format_time, FullException, FullLogLine, Trace};
use crate::ui::style::TABLE_HEADER_STYLE;
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
use ratatui::prelude::*;
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
use std::iter::once;
pub fn single_log(app: &App, line: &LogLine) -> SingleLog {
let raw_line = app.get_line(line.index);
let line = raw_line.and_then(|raw_line| parse_line_full(raw_line).ok());
pub fn single_log(line: &FullLogLine) -> SingleLog {
SingleLog::new(line)
}
pub struct SingleLog {
line: Option<FullLogLine>,
pub struct SingleLog<'a> {
line: &'a FullLogLine,
path_prefix_length: usize,
}
impl SingleLog {
pub fn new(line: Option<FullLogLine>) -> Self {
impl<'a> SingleLog<'a> {
pub fn new(line: &'a FullLogLine) -> Self {
let path_prefix_length = line
.exception
.as_ref()
.and_then(|line| line.exception.as_ref())
.map(|ex| find_path_prefix_length(ex.trace.iter().map(|t| t.file.as_str())))
.unwrap_or_default();
SingleLog {
@ -32,14 +28,14 @@ impl SingleLog {
}
}
impl StatefulWidget for SingleLog {
impl StatefulWidget for SingleLog<'_> {
type State = ScrollbarTableState;
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
where
Self: Sized,
{
if let Some(line) = self.line {
let line = self.line;
let par = Paragraph::new(format!(
"{}\n\n {} {}\n {}\n\n {} from {} by {} at {} - Nextcloud {}",
line.message,
@ -88,10 +84,6 @@ impl StatefulWidget for SingleLog {
);
}
}
} else {
let par = Paragraph::new("Failed to parse log line").wrap(Wrap::default());
par.render(area, buf);
}
}
}

View file

@ -110,7 +110,6 @@ impl<'a> LogsState<'a> {
UiState::Log(LogState {
log,
full_line,
trace_len,
table_state,
previous: Box::new(self.into()),
})
@ -137,7 +136,6 @@ impl PartialEq for ErrorState<'_> {
#[derive(Clone)]
pub struct LogState<'a> {
pub trace_len: usize,
pub log: &'a LogLine<'a>,
pub full_line: FullLogLine,
pub table_state: ScrollbarTableState,