labstack / gommon

Common packages for Go
MIT License
536 stars 100 forks source link

Log crashes in ConEmu in Windows but not in mintty #2

Closed aboukirev closed 8 years ago

aboukirev commented 8 years ago

Logging crashes with "runtime error: index out of range" in the log() function on line 173

f := fmt.Sprintf("%s|%s|%v\n", levels[v], l.prefix, msg)

in Windows in ConEmu console window. Works fine but no colors in mintty. My guess is ConEmu console is not recognized as *os.File and variable levels is not initialized. In my case log() is called from Info() so the level is INFO or 2, which I can see in the stack trace of panic output.

Perhaps, levels should always be initialized to some sensible values in SetOutput().

vishr commented 8 years ago

@aboukirev I have fixed the crashing issue. I would need you help to find what's the type of your io.Writer. os.Stdout is *os.File.

aboukirev commented 8 years ago

@vishr Apparently go-colorable, when built in Windows, returns colorable.Writer (extends io.Writer. For other systems it returns os.Stdout (which also implements io.Writer). mintty is part of msys2 toolchain that I am running and behaves as *nix/Posix, hence no issue there.

Verified your latest fix is working perfectly well. Thank you.

vishr commented 8 years ago

@aboukirev Did another commit, can you check if windows is getting colors?

aboukirev commented 8 years ago

@vishr Yes, the coloring works in both ConEmu and mintty. This is most excellent.

vishr commented 8 years ago

Cool.