You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In log formatting, consistent and readable output is critical for debugging and analysis. Fields like log levels (INFO, WARNING) often have variable lengths, making the output misaligned. A field width with alignment formatter ensures that fields occupy consistent space in the output, improving readability and enabling proper alignment.
Problem:
The log levels (I, D3) have variable lengths:
I is 1 character.
D3 is 2 characters.
Without padding, the alignment of subsequent fields (e.g., [conn11]) shifts, making the logs harder to read at a glance.
Solution:
Using a field width formatter, the log levels can be aligned to a fixed width (e.g., 2 characters) by padding shorter levels and ensuring uniform spacing.
Desired output:
The proposal makes sense, but now I'm wondering how this works for fields of different types and whether that might be confusing to users.
For instance, we could allow using this formatter on all field types, and then we simply pad the stringified version of the field. This would work in most cases, but for a negative float field where the user wants to 0-pad it on the left, this formatter wouldn't work (since the 0 padding would be placed left of the negative sign, e.g., "000-5.5"). So in this case, we'd probably need a numeric padding formatter, right? That's also doable, but I have a feeling that a padding formatter could handle both if we made the syntax more advanced somehow. But then again, I haven't thought it through and there might be limitations to trying to handle both.
Request
In log formatting, consistent and readable output is critical for debugging and analysis. Fields like log levels (INFO, WARNING) often have variable lengths, making the output misaligned. A field width with alignment formatter ensures that fields occupy consistent space in the output, improving readability and enabling proper alignment.
Use Case Analysis: Example Logs
Input Example:
Problem:
The log levels (I, D3) have variable lengths:
I
is 1 character.D3
is 2 characters.Without padding, the alignment of subsequent fields (e.g., [conn11]) shifts, making the logs harder to read at a glance.
Solution:
Using a field width formatter, the log levels can be aligned to a fixed width (e.g., 2 characters) by padding shorter levels and ensuring uniform spacing.
Desired output:
Key Features
Possible implementation
Field width formatter syntax
Field formatter name:
field_width
Options string syntax:
<width>[[;<left|center|right>];<delimiter>]
Components of the syntax:
<width>
(Required). Examples:10
: Ensures the field is at least 10 characters wide.[;<left|center|right>]
(Optional unless a delimiter is specified). Examples:10;center
: Ensures the field is 10 characters wide, with content centered.15;right
: Ensures the field is 15 characters wide, with content right-aligned.[;<fill>]
(Optional). Examples:10;left;-
: Ensures the field is 10 characters wide, left-aligned, with - for padding.8;right;*
: Ensures the field is 8 characters wide, right-aligned, with * for padding.Reference
Inspired by:
The text was updated successfully, but these errors were encountered: