From fabe3df78528c0fb17fc9abde5c80de8057f3b89 Mon Sep 17 00:00:00 2001 From: Javier Provecho Fernandez Date: Sat, 3 Dec 2016 22:11:24 +0100 Subject: [PATCH 1/3] Revert "Revert "Merge pull request #744 from aviddiviner/logger-fix"" This reverts commit 19f271c86ba04f2d56d342c20a3f1b16fe785c23. --- logger.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/logger.go b/logger.go index d56bc62..b4743a7 100644 --- a/logger.go +++ b/logger.go @@ -7,7 +7,10 @@ package gin import ( "fmt" "io" + "os" "time" + + "golang.org/x/crypto/ssh/terminal" ) var ( @@ -44,6 +47,11 @@ func Logger() HandlerFunc { // LoggerWithWriter instance a Logger middleware with the specified writter buffer. // Example: os.Stdout, a file opened in write mode, a socket... func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc { + isTerm := true + if outFile, ok := out.(*os.File); ok { + isTerm = terminal.IsTerminal(int(outFile.Fd())) + } + var skip map[string]struct{} if length := len(notlogged); length > 0 { @@ -71,8 +79,11 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc { clientIP := c.ClientIP() method := c.Request.Method statusCode := c.Writer.Status() - statusColor := colorForStatus(statusCode) - methodColor := colorForMethod(method) + var statusColor, methodColor string + if isTerm { + statusColor = colorForStatus(statusCode) + methodColor = colorForMethod(method) + } comment := c.Errors.ByType(ErrorTypePrivate).String() fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s", From 38e4b1d2fe5b0890dd2f72def7d5852b4a25984f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 4 Dec 2016 09:50:02 +0800 Subject: [PATCH 2/3] Support google appengine for IsTerminal func. Signed-off-by: Bo-Yi Wu --- logger.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/logger.go b/logger.go index ad442d0..7c2a72b 100644 --- a/logger.go +++ b/logger.go @@ -8,10 +8,9 @@ import ( "fmt" "io" "os" - "runtime" "time" - "golang.org/x/crypto/ssh/terminal" + "github.com/mattn/go-isatty" ) var ( @@ -50,10 +49,8 @@ func Logger() HandlerFunc { func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc { isTerm := true - if runtime.GOOS != "appengine" && runtime.GOOS != "netbsd" && runtime.GOOS != "openbsd" { - if outFile, ok := out.(*os.File); ok { - isTerm = terminal.IsTerminal(int(outFile.Fd())) - } + if w, ok := out.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) { + isTerm = false } var skip map[string]struct{} From 83e2ea2e6b4fe9d43e5cec0bda3de4dde6e466ed Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 4 Dec 2016 09:56:14 +0800 Subject: [PATCH 3/3] testing on go latest version. Signed-off-by: Bo-Yi Wu --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3305174..53f436f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: go sudo: false go: - 1.4 - - 1.5 - - 1.6 - - 1.7 + - 1.5.4 + - 1.6.4 + - 1.7.4 - tip script: