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
Do not assume no color on windows. #957
base: master
Are you sure you want to change the base?
Conversation
recent windows 10 can support colour (it is even enabled in logrus) however the default formatter does not use colour and so the default log format is different on windows to other OSes when logging to the terminal. This removed the hard code no colour for windows terminals to be consistent with other OSes fixes sirupsen#763
Now that windows coloring behaves correctly the unit test for text_formatter was incorrect. changes the expected test output to be the same regardless of the OS.
@jtnord there have been back and forth pull request on this topic. |
Windows 10 has according to this site more than 50% of the windows desktop market and given the updates are pushed pretty hard, and the version that has ANSI support is pretty old now it would suggest that the switch over point to flip the behaviour is here or very close. (see also this page for an old breakdown of versions I guess whilst we can endlessly debate the use of color vs no color the issue we have is that this drives not the use of colour but the output format, and this change does not address that, it was just a simple enough fix for my needs (#763) |
@dgsb the reason for my initial PR on this topic was - as i stated there - not that windows 10 was uncapable of supporting colours, it just was not supported by default, you had to turn it on manually (as in the thread linked by @cup). While definitely is possible to use colours, if you know what you are doing, it will not work for most users that have not explicitly enabled it. Another fix could be to just check the registry for the key, but i don't think that would be worth the effort and costs |
After looking at this more closely I am actually a fan of this. Windows 10 ANSI https://superuser.com/questions/413073/-/1300251 but they still work if the application specifies it, which Logrus does: Line 16 in f0375eb
For earlier Windows versions it would help if #965 was fixed as well. Currently package main
import "github.com/mattn/go-colorable"
import "github.com/sirupsen/logrus"
func main() {
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
logrus.SetOutput(colorable.NewColorableStdout())
logrus.Info("aaaaa bbbbb")
} and this for Windows 10: package main
import "github.com/sirupsen/logrus"
func main() {
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
logrus.Info("aaaaa bbbbb")
} If this issue was fixed as well as #965, this could be used for Linux, package main
import "github.com/sirupsen/logrus"
func main() {
logrus.Info("aaaaa bbbbb")
} |
I didn't notice this PR already existed, but I just opened #974 which addresses the old Windows version issue by detecting when EnableVirtualTerminalProcessing fails, and falling back to no colors in that case. It should allow colors on new Windows versions without impacting output on old versions. |
recent windows 10 can support colour (it is even enabled in logrus)
however the default formatter does not use colour and so the default log
format is different on windows to other OSes when logging to the
terminal. This removed the hard code no colour for windows terminals to
be consistent with other OSes
fixes #763