Skip to content

Commit

Permalink
feat: add min_size and make it default
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Oct 4, 2024
1 parent 0f8e783 commit af15bb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ handlebar helpers:
- uppercase
- level_style
- fixed_size 10
- min_size 10

## NO_COLOR

Expand Down
2 changes: 1 addition & 1 deletion default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ dump_all_exclude = []
always_print_fields = []
level_keys = ["level", "severity", "log.level", "loglevel"]
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}}"
additional_value_format = "{{bold (color_rgb 150 150 150 (min_size 25 key))}}: {{value}}"

[level_map]
13 changes: 12 additions & 1 deletion src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use yansi::{Color, Paint};

pub static DEFAULT_MAIN_LINE_FORMAT: &str =
"{{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}}";
pub static DEFAULT_ADDITIONAL_VALUE_FORMAT: &str = "{{bold (color_rgb 150 150 150 (min_size 25 key))}}: {{value}}";

pub fn fblog_handlebar_registry(main_line_format: String, additional_value_format: String) -> Handlebars<'static> {
handlebars_helper!(bold: |t: str| {
Expand Down Expand Up @@ -67,12 +67,23 @@ pub fn fblog_handlebar_registry(main_line_format: String, additional_value_forma
}
});

handlebars_helper!(min_size: |isize: u64, t: str| {
let x = t.to_string();
let size = isize.try_into().expect("should fit");
if x.len() < size {
format!("{}{}", " ".repeat(size - x.len()), x)
} else {
x
}
});

let mut reg = Handlebars::new();
reg.register_escape_fn(Box::new(no_escape));

reg.register_helper("bold", Box::new(bold));
reg.register_helper("uppercase", Box::new(uppercase));
reg.register_helper("fixed_size", Box::new(fixed_size));
reg.register_helper("min_size", Box::new(min_size));
reg.register_helper("level_style", Box::new(level_style));

reg.register_helper("yellow", Box::new(yellow));
Expand Down

0 comments on commit af15bb7

Please sign in to comment.