diff --git a/default_config.toml b/default_config.toml index 7821ba7..c9cc12e 100644 --- a/default_config.toml +++ b/default_config.toml @@ -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}}" diff --git a/src/log.rs b/src/log.rs index 4da111c..fac5597 100644 --- a/src/log.rs +++ b/src/log.rs @@ -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, ""); @@ -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), diff --git a/src/template.rs b/src/template.rs index dd298b2..41edcd2 100644 --- a/src/template.rs +++ b/src/template.rs @@ -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 {