-
Notifications
You must be signed in to change notification settings - Fork 147
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
Detect windows and use non-colored stdout logs? #13
Comments
Ouch, yeah, that's quite possible. What type of terminal were you using, cmd.exe or Powershell, or one of the other variants? For now, I'd suggest you do something like:
|
I usually use Linux, was just investigating a crash report in windows, so I've got nothing fancy installed, just cmd.exe. I was also thinking about some similar solution, but since I'm using this in a library (https://github.com/project-iris/iris-go#logging) where anybody can override the default log settings, is there a way to "force" colorless logging even if the user changes some of the settings? (I'm not familiar with the log15 internals, hence my question :) ). |
You can force colorless logging with this code:
By default, when log15 init()'s, it checks if os.Stdout is a terminal, and if it is, uses log.TerminalFormat() which does the color formatting. Explicitly setting it to LogfmtFormat() or JsonFormat() will force no colorization. |
What about using the recently announced github.com/mattn/go-colorable package to get color for Windows too? |
thanks for pointing that out! i'm going to take a look at using mattn's package for this |
proper colors on windows thanks to mattn. fixes #13
I've just ran some code based on log15 under Windows and saw that the output is quite chaotic due to windows not recognizing the color defs and hence dumping a lot of extra characters all over the logs. At least this is my hunch, didn't really have time to track it down. Maybe you could add a build flag to disable colors if running on windows?
The text was updated successfully, but these errors were encountered: