Gin: Debug output formatted incorrectly in Windows

Created on 13 Jun 2017  路  9Comments  路  Source: gin-gonic/gin

When I run this service on OS X, output is as expected, but in Windows there are characters that are unable to be displayed.

Windows 10

[GIN-debug] Listening and serving HTTP on 127.0.0.1:6969
[GIN] 2017/06/13 - 13:42:26 | 404 |            0s | 127.0.0.1 |   GET     /c
[GIN] 2017/06/13 - 13:42:30 | 404 |       501.3碌s | 127.0.0.1 |   GET     /favicon.ico
[GIN] 2017/06/13 - 13:43:26 | 200 |            0s | 127.0.0.1 |   GET     /api/v1/c

image

bug

Most helpful comment

@SCKelemen could you please try again as follows?

To support coloring in Windows use:

import "github.com/mattn/go-colorable"
gin.DefaultWriter = colorable.NewColorableStdout()

https://github.com/gin-gonic/gin/blob/master/mode.go#L31

All 9 comments

mattn/go-colorable seems to be a popular way of doing cross-platform color escape codes.

Might be worth refactoring the hard-coded ANSI escape codes in logger.go to use this?

@SCKelemen could you please try again as follows?

To support coloring in Windows use:

import "github.com/mattn/go-colorable"
gin.DefaultWriter = colorable.NewColorableStdout()

https://github.com/gin-gonic/gin/blob/master/mode.go#L31

How strange. Everything displays fine for me

But maybe it's because I run everything through ConEmu and not the raw command prompt...
I remember having issues with those color tags months ago, but they suddenly disappeared one day 馃槃

Under OS X, there seems to be a bug in that package where the line color is never reset:
screen shot 2017-06-14 at 17 34 58
screen shot 2017-06-14 at 17 34 36
This appears to be a bug though.... I was playing around with it earlier, and it seems like it's due to some unfriendly conventions. https://github.com/sckelemen/gocat

Under Windows 10, cmd.exe, there bug persists:

$ go get
$ go run main.go

image
Running with powershell

$ powershell
$ go run .\main.go

It seems to work, and not have the line feed bug
image

Running with Bash on Windows 10 also fails to color

$ go get
$ go run main.go

image

You can get the test code at https://github.com/sckelemen/mstodo

If you want me to try it with CMDr or some other shell/terminal emulator, let me know

@SCKelemen Working on my MacOS

screen shot 2017-06-16 at 10 01 25 am

@SCKelemen maybe you should try the following solution on Windows.

import "github.com/mattn/go-colorable"

gin.DefaultWriter = colorable.NewColorableStdout()

the solution works. thanks.

could you make this default in codes of gin, or document it in the tutorial of Github page of gin? that's better maybe

I found gin will not print color depend on detected TTY.

but actually at first gin show square in debug log like the pic of first one comment. after using the solution go-colorable, it stop print square but still no color. it finally print color by using gin.ForceConsoleColor().

so it detected the TTY, and not print color but do print square.
hope fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilee picture lilee  路  3Comments

rawoke083 picture rawoke083  路  3Comments

ghost picture ghost  路  3Comments

cxk280 picture cxk280  路  3Comments

oryband picture oryband  路  3Comments