Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure log levels are appropriately padded even on coloured outputs. #69

Merged
merged 1 commit into from Oct 19, 2022
Merged

Conversation

etemesi254
Copy link
Contributor

Hi,

First of all thanks for the library.

There was an issue when having colored output on Linux(Manjaro Linux with KDE to be specific), where coloured outputs had mis-padded logging

image

The issue came about with how coloring is done on Linux, i.e we add special characters in the command line, e.g printing color red would add \033[39m,

Later on, when you tried to format the message with appropriate padding, for log levels

            let message = format!(
                "{}{:<5} [{}{}] {}",
                timestamp,
                level_string,
                target,...);

The colored log levels would not be padded because the string is longer than 5 characters, hence the misalignment above.

The fix was to simply do the padding before the coloring which fixes that misalignment,
now with this pr the printed output looks like

image

This is now in tandem with the no color output which would print with the appropriate padding

Hope it helps.

@borntyping
Copy link
Owner

Thanks!

This is currently failing to pass the linter, though the suggested diff is horrid enough that I'm going to look at configuring it to allow slightly longer lines before reflowing code instead of changing this MR.

@borntyping borntyping merged commit 1ed54e3 into borntyping:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants