Skip to content

Commit

Permalink
fix: prefix formatting should be done by the template
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Nov 29, 2023
1 parent ff477ab commit 5a5449c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion default_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
message_keys = ["short_message", "msg", "message"]
time_keys = ["timestamp", "time", "@timestamp"]
level_keys = ["level", "severity", "log.level", "loglevel"]
main_line_format = "{{bold(fixed_size 19 fblog_timestamp)}} {{level_style (uppercase (fixed_size 5 fblog_level))}}:{{bold(cyan fblog_prefix)}} {{fblog_message}}"
main_line_format = "{{bold(fixed_size 19 fblog_timestamp)}} {{level_style (uppercase (fixed_size 5 fblog_level))}}:{{#if fblog_prefix}} {{bold(cyan fblog_prefix)}}{{/if}} {{fblog_message}}"
additional_value_format = "{{bold (color_rgb 150 150 150 (fixed_size 25 key))}}: {{value}}"
4 changes: 2 additions & 2 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn print_log_line(
let string_log_entry = flatten_json(log_entry, "");
let level = get_string_value_or_default(&string_log_entry, &log_settings.level_keys, "unknown");

let formatted_prefix = maybe_prefix.map(|p| format!(" {}", p)).unwrap_or_else(|| "".to_owned());
let trimmed_prefix = maybe_prefix.map(|p| p.trim()).unwrap_or_else(|| "").to_string();
let mut message = get_string_value_or_default(&string_log_entry, &log_settings.message_keys, "");
let timestamp = get_string_value_or_default(&string_log_entry, &log_settings.time_keys, "");

Expand All @@ -31,7 +31,7 @@ pub fn print_log_line(
handle_bar_input.insert("fblog_timestamp".to_string(), Value::String(timestamp));
handle_bar_input.insert("fblog_level".to_string(), Value::String(level));
handle_bar_input.insert("fblog_message".to_string(), Value::String(message));
handle_bar_input.insert("fblog_prefix".to_string(), Value::String(formatted_prefix));
handle_bar_input.insert("fblog_prefix".to_string(), Value::String(trimmed_prefix));

let write_result = match handlebars.render("main_line", &handle_bar_input) {
Ok(string) => writeln!(out, "{}", string),
Expand Down
2 changes: 1 addition & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::convert::TryInto;
use yansi::{Color, Style};

pub static DEFAULT_MAIN_LINE_FORMAT: &str =
"{{bold(fixed_size 19 fblog_timestamp)}} {{level_style (uppercase (fixed_size 5 fblog_level))}}:{{bold(cyan fblog_prefix)}} {{fblog_message}}";
"{{bold(fixed_size 19 fblog_timestamp)}} {{level_style (uppercase (fixed_size 5 fblog_level))}}:{{#if fblog_prefix}} {{bold(cyan fblog_prefix)}}{{/if}} {{fblog_message}}";
pub static DEFAULT_ADDITIONAL_VALUE_FORMAT: &str = "{{bold (color_rgb 150 150 150 (fixed_size 25 key))}}: {{value}}";

fn level_to_style(level: &str) -> Style {
Expand Down

0 comments on commit 5a5449c

Please sign in to comment.