mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
log time
This commit is contained in:
parent
6e0c662fb4
commit
e7b70fd00e
6 changed files with 41 additions and 8 deletions
|
|
@ -1,14 +1,17 @@
|
|||
use cloud_log_analyser_data::LogLevel;
|
||||
use serde::Deserialize;
|
||||
use time::OffsetDateTime;
|
||||
use tinystr::TinyAsciiStr;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LogLine {
|
||||
pub version: TinyAsciiStr<8>,
|
||||
pub version: TinyAsciiStr<16>,
|
||||
pub level: LogLevel,
|
||||
pub message: String,
|
||||
pub exception: Option<Exception>,
|
||||
pub app: TinyAsciiStr<16>,
|
||||
pub app: TinyAsciiStr<32>,
|
||||
#[serde(with = "time::serde::iso8601")]
|
||||
pub time: OffsetDateTime,
|
||||
}
|
||||
|
||||
impl LogLine {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,13 @@ fn main() -> MainResult {
|
|||
|
||||
let mut counts: HashMap<MatchResult, Vec<usize>> = HashMap::new();
|
||||
let first = lines.next().unwrap();
|
||||
let first_parsed: LogLine = serde_json::from_str(&first).unwrap();
|
||||
let first_parsed: LogLine = match serde_json::from_str(&first) {
|
||||
Ok(first_parsed) => first_parsed,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to parse the first line in the log: {:#}", e);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let statements = get_statements(first_parsed.major_version().unwrap_or(MAX_VERSION));
|
||||
let matcher = Matcher::new(&statements);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
use crate::app::{App, LogMatch};
|
||||
use crate::logline::LogLine;
|
||||
use crate::ui::style::{TABLE_HEADER_STYLE, TABLE_SELECTED_STYLE};
|
||||
use crate::ui::style::{TABLE_HEADER_STYLE, TABLE_SELECTED_STYLE, TIME_FORMAT};
|
||||
use ratatui::layout::Constraint;
|
||||
use ratatui::widgets::{Cell, HighlightSpacing, Row, Table};
|
||||
use time::format_description::well_known::Iso8601;
|
||||
|
||||
pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
|
||||
let lines = matches.lines.iter().map(|i| &app.lines[*i]);
|
||||
|
||||
let header = ["Level", "App", "Message"]
|
||||
let header = ["Level", "App", "Message", "Date"]
|
||||
.into_iter()
|
||||
.map(Cell::from)
|
||||
.collect::<Row>()
|
||||
|
|
@ -18,6 +19,7 @@ pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
|
|||
Constraint::Min(10),
|
||||
Constraint::Min(20),
|
||||
Constraint::Percentage(100),
|
||||
Constraint::Min(30),
|
||||
];
|
||||
let table = Table::new(lines.map(|line| log_row(line)), widths)
|
||||
.header(header)
|
||||
|
|
@ -28,8 +30,9 @@ pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
|
|||
|
||||
fn log_row(line: &LogLine) -> Row {
|
||||
Row::new([
|
||||
line.level.as_str(),
|
||||
line.app.as_str(),
|
||||
line.message.as_str(),
|
||||
line.level.as_str().to_string(),
|
||||
line.app.to_string(),
|
||||
line.message.clone(),
|
||||
line.time.format(&Iso8601::<TIME_FORMAT>).unwrap(),
|
||||
])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
use ratatui::prelude::Style;
|
||||
use ratatui::style::palette::tailwind;
|
||||
use time::format_description::well_known::iso8601::{Config, EncodedConfig, TimePrecision};
|
||||
|
||||
pub const TABLE_HEADER_STYLE: Style = Style::new().bg(tailwind::BLACK).fg(tailwind::GREEN.c600);
|
||||
pub const TABLE_SELECTED_STYLE: Style = Style::new().fg(tailwind::BLACK).bg(tailwind::GREEN.c600);
|
||||
pub const TIME_FORMAT: EncodedConfig = Config::DEFAULT
|
||||
.set_time_precision(TimePrecision::Second {
|
||||
decimal_digits: None,
|
||||
})
|
||||
.encode();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue