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

Remove colored output on windows #864

Merged
merged 3 commits into from Dec 10, 2018
Merged

Remove colored output on windows #864

merged 3 commits into from Dec 10, 2018

Conversation

ceriath
Copy link
Contributor

@ceriath ceriath commented Nov 16, 2018

Fixes #862

Currently the textformatter on windows outputs

←[31mERRO←[0m[0000] test windows

when coloring is not disabled explicitly.
However, windows up to windows 8.1 does not support colored output on cmd entirely. Windows 10 added support for it, which is off by default and has to be enabled via registry or environment variable. Therefore i suggest removing colored output on windows entirely to make the output usable again.

Currently the textformatter on windows outputs 

``←[31mERRO←[0m[0000] test windows``

when coloring is not disabled explicitly.
However, windows up to windows 8.1 does not support colored output on cmd entirely. Windows 10 added support for it, which is off by default and has to be enabled via registry or environment variable. Therefore i suggest removing colored output on windows entirely to make the output usable again.
@@ -102,7 +103,7 @@ func (f *TextFormatter) isColored() bool {
}
}

return isColored && !f.DisableColors
return isColored && !f.DisableColors && (runtime.GOOS != "windows")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I would like that the ForceColor field of the text formatter takes precedence on the environment check.
I expect that then this flag is set to true the user knows what he is doing.

@@ -443,7 +444,11 @@ func TestTextFormatterIsColored(t *testing.T) {
os.Setenv("CLICOLOR_FORCE", val.clicolorForceVal)
}
res := tf.isColored()
assert.Equal(subT, val.expectedResult, res)
if runtime.GOOS == "windows" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to updated the test for windows environment where isColored always return false except when ForceColor is set to true.

@dgsb
Copy link
Collaborator

dgsb commented Dec 9, 2018

@ceriath thanks for your contribution, I've added a few comments on you change. Let me know what you think.

@ceriath
Copy link
Contributor Author

ceriath commented Dec 9, 2018

@dgsb i agree, i changed it so setting ForceColor or the environment variables takes precedence. With the environment variables users who explicitly turned on colored output have an easy way to also enable it on logrus without recompiling the application

@dgsb
Copy link
Collaborator

dgsb commented Dec 10, 2018

@ceriath that's exactly what I had in mind.

@dgsb dgsb merged commit 9f04967 into sirupsen:master Dec 10, 2018
cgxxv pushed a commit to cgxxv/logrus that referenced this pull request Mar 25, 2022
Remove colored output on windows
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