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
There are not a Windows support. It supports only ANSI-colors. ANSI-colors are escape codes like \033[31m, \033[0m, etc. For example \033[36m is cyan color.
There is github.com/mattn/go-colorable package that wraps windows output to print ANSI-colors correct. I'm not sure that it works. Here is a research of someone: image.
If you use log package (not fmt) then you can use SetOutput method. For example
This way, output of log-functions will be handled by the colorable package and colorized correctly (not sure).
Feel free to ask if it is not clear enough.
I just checked the source code of github.com/mattn/go-colorable; its functions are based on importing kernel32.dll and the corresponding Windows APIs, which doesn't seem to be a graceful workaround but at least works.
You can to use the isatty package with aurora.NewAurora (see README for example). The aurora package uses another approach to turn on/off colors. This way, you can keep colors if you want (even output is a file).
I just checked the source code of github.com/mattn/go-colorable; its functions are based on importing kernel32.dll and the corresponding Windows APIs, which doesn't seem to be a graceful workaround but at least works.
If you are worried about the 32, the kernel32.dll is for 32- and 64-bit systems too.
About "replace the strings unconditionally". There is some overhead, anyway. For example, if colors disabled Cyan("string") wraps the "string" with some internal struct to get Value interface instead of string. Thus, all overheads of log.Print(Cyan("string")) is "string" -> interface{}(...) -> struct{...} -> fmt.Sprint(...) -> the result used by log.Print. And steps that cost are: (1) conversion to interface{} (2) call of fmt.Sprint.
May be, the package is not best solution for high performance logs, if colors are switched off. The goal was usability. However, it can be faster then other packages, if colors are switched on.
Also, the package provided with good set of benchmarks.
Activity
logrusorgru commentedon May 3, 2017
There are not a Windows support. It supports only ANSI-colors. ANSI-colors are escape codes like
\033[31m,\033[0m, etc. For example\033[36mis cyan color.There is github.com/mattn/go-colorable package that wraps windows output to print ANSI-colors correct. I'm not sure that it works. Here is a research of someone: image.
If you use
logpackage (notfmt) then you can use SetOutput method. For exampleThis way, output of
log-functions will be handled by thecolorablepackage and colorized correctly (not sure).Feel free to ask if it is not clear enough.
godoc links:
Equim-chan commentedon May 3, 2017
I know that's ANSI color, but it just becomes weird when the same trick works fine in other languages.
For example in Nodejs,
Tools from MinGW that support color also work well, like
ls --colorandgrep --color.Also, my shell is cmder actually, but it runs over cmd.
logrusorgru commentedon May 3, 2017
Hm, I need reboot to explore the issue. I think that Nodejs has some internal workaround. A moment.
Equim-chan commentedon May 3, 2017
I just checked the source code of github.com/mattn/go-colorable; its functions are based on importing kernel32.dll and the corresponding Windows APIs, which doesn't seem to be a graceful workaround but at least works.
logrusorgru commentedon May 3, 2017
Windows 7 x64. First output uses the

colorable. Second one don't use it. And nodejs output for example.Equim-chan commentedon May 3, 2017
Thanks for the testing. One other question is, does this package replace the strings unconditionally? Does it detect the tty context?
logrusorgru commentedon May 3, 2017
Yes, I think. Take a look https://github.com/mattn/go-colorable/blob/master/colorable_windows.go#L88. It uses
isattypackageEquim-chan commentedon May 3, 2017
Well, I mean in your aurora package.
logrusorgru commentedon May 3, 2017
No, never.
Equim-chan commentedon May 3, 2017
Hmm, that's not good when stdout is piped to a log file, which does not need colors.
logrusorgru commentedon May 3, 2017
You can to use the
isattypackage withaurora.NewAurora(see README for example). Theaurorapackage uses another approach to turn on/off colors. This way, you can keep colors if you want (even output is a file).logrusorgru commentedon May 3, 2017
For example (the example works fine)
logrusorgru commentedon May 3, 2017
Also. The colorizer has the same set of methods as the
aurorapackae. I.e. you can call itaurorainstead ofauto avoid renaming everywhere.But. Colors are package-level (BoldFg, BlueBg etc)
logrusorgru commentedon May 3, 2017
If you are worried about the 32, the
kernel32.dllis for 32- and 64-bit systems too.logrusorgru commentedon May 4, 2017
About "replace the strings unconditionally". There is some overhead, anyway. For example, if colors disabled
Cyan("string")wraps the "string" with some internal struct to get Value interface instead of string. Thus, all overheads oflog.Print(Cyan("string"))is"string"->interface{}(...)->struct{...}->fmt.Sprint(...)-> the result used by log.Print. And steps that cost are: (1) conversion tointerface{}(2) call offmt.Sprint.May be, the package is not best solution for high performance logs, if colors are switched off. The goal was usability. However, it can be faster then other packages, if colors are switched on.
Also, the package provided with good set of benchmarks.