spdlog-rs
spdlog-rs copied to clipboard
[Feature Request] Support formatting parameters in pattern placeholders
spdlog
supports specifying text alignment in its pattern flags, see https://github.com/gabime/spdlog/wiki/3.-Custom-formatting#aligning:
-
%8l
requires right alignment and will expand toinfo
; -
%-8l
requires left alignment and will expand toinfo
; -
%=8l
requires center alignment and will expand toinfo
.
Besides, an additional !
can be used to truncate the expanded result if it's too wide:
-
%3!l
,%-3!l
, and%=3!l
will expand toinf
.
This feature can be neat sometimes and maybe we could also support this. We may follow the convention of format!
and propose the following new pattern placeholder syntax:
placeholder := '{' NAME [ ':' format_spec ] '}'
format_spec := [ [fill] align ] [ ['.'] width ]
fill := CHAR
align := INT
width := INT
Some examples:
-
{level:8}
and{level:<8}
will expand toinfo
(left alignment, pad with spaces); -
{level:-<8}
will expand toinfo----
(left alignment, pad with-
); -
{level:>8}
will expand toinfo
(right alignment, pad with spaces); -
{level:->8}
will expand to----info
(right alignment, pad with-
); -
{level:^8}
will expand toinfo
(center alignment, pad with spaces); -
{level:-^8}
will expand to--info--
(center alignment, pad with-
); -
{level:.3}
will expand toinf
(left alignment, truncate field to 3 characters long).