Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
511 changes: 202 additions & 309 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "log_viewer"
version = "0.3.3"
version = "0.3.4"
edition = "2021"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Context};
use data::filter::{Comparator, FieldSpecifier, FilterConfig, FilterOn};
use egui::{
text::{CCursor, CCursorRange},
Align, KeyboardShortcut,
Align, KeyboardShortcut, Label,
};
use egui_extras::{Column, TableBuilder};
use shortcut::Shortcuts;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl LogViewerApp {
.unwrap_or(&default_text_color);
ui.colored_label(*color, display_value);
} else {
ui.label(display_value);
ui.add(Label::new(display_value).truncate());
}
}
});
Expand Down
22 changes: 14 additions & 8 deletions src/app/data.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet},
use super::{
calculate_hash,
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling},
};

use anyhow::Context;
use data_iter::DataIter;
use filter::{FieldSpecifier, FilterConfig};
use serde_json::Value;
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet},
};
use tracing::warn;

use super::{
calculate_hash,
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling},
};
mod data_iter;
pub mod filter;

Expand Down Expand Up @@ -367,6 +366,7 @@ impl TryFrom<(&DataDisplayOptions, usize, &str)> for LogRow {
fn try_from(
(data_display_options, row_idx_val, value): (&DataDisplayOptions, usize, &str),
) -> Result<Self, Self::Error> {
let row_size_in_bytes = value.len();
let data = match serde_json::from_str::<BTreeMap<String, Value>>(value) {
Ok(data) => data,
Err(e) => match &data_display_options.row_parse_error_handling {
Expand Down Expand Up @@ -398,6 +398,12 @@ impl TryFrom<(&DataDisplayOptions, usize, &str)> for LogRow {
result.or_insert(key, value);
}
}
if let Some(config) = data_display_options.row_size_config.as_ref() {
result.or_insert(
config.field_name.clone(),
config.units.convert(row_size_in_bytes),
);
}
Ok(result)
}
}
Expand Down
43 changes: 42 additions & 1 deletion src/app/data_display_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ pub struct DataDisplayOptions {

/// Used for optionally converting message levels to strings
pub level_conversion: Option<LevelConversion>,

/// Used for optionally including the size of messages
pub row_size_config: Option<RowSizeConfig>,
}

#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
#[serde(default)]
pub struct FieldColoringRules {
/// Matches a field value to color
pub value_color_map: BTreeMap<String, Color32>,
Expand All @@ -45,6 +49,7 @@ pub enum RowParseErrorHandling {
}

#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
#[serde(default)]
pub struct LevelConversion {
/// Skips record if field name already exists
pub display_field_name: String,
Expand All @@ -53,6 +58,37 @@ pub struct LevelConversion {
pub convert_map: BTreeMap<i64, String>,
}

#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
#[serde(default)]
pub struct RowSizeConfig {
pub field_name: String,
pub units: SizeUnits,
}

#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
pub enum SizeUnits {
Bytes,
#[default]
KB,
MB,
GB,
TB,
// TODO 5: Add an auto option to use smallest non fractional (would need to use str instead of f32)
}
impl SizeUnits {
pub(crate) fn convert(&self, row_size_in_bytes: usize) -> serde_json::Value {
let scalar = match self {
SizeUnits::Bytes => 1.0,
SizeUnits::KB => 1024.0,
SizeUnits::MB => 1024.0 * 1024.0,
SizeUnits::GB => 1024.0 * 1024.0 * 1024.0,
SizeUnits::TB => 1024.0 * 1024.0 * 1024.0 * 1024.0,
};
let result = row_size_in_bytes as f64 / scalar;
result.into()
}
}

impl DataDisplayOptions {
pub fn main_list_fields(&self) -> &[String] {
&self.main_list_fields
Expand All @@ -72,6 +108,7 @@ impl Default for DataDisplayOptions {
main_list_fields: [
"row#",
"level_str",
"row_size",
"time",
"request_id",
"otel.name",
Expand Down Expand Up @@ -108,6 +145,10 @@ impl Default for DataDisplayOptions {
.collect(),
emphasize_if_matching_field_idx: Some(3),
row_idx_field_name: Some("row#".to_string()),
row_size_config: Some(RowSizeConfig {
field_name: "row_size".to_string(),
units: SizeUnits::Bytes,
}),
row_parse_error_handling: Default::default(),
level_conversion: Some(Default::default()),
colored_fields: [(
Expand Down
Loading
Loading