Skip to content

Commit e2212d4

Browse files
v1.1.4
# Conflicts: # logger.go
2 parents 041ca04 + 18392f5 commit e2212d4

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: go
22
sudo: false
33
go:
44
- 1.4
5-
- 1.5
6-
- 1.6
7-
- 1.7
5+
- 1.5.4
6+
- 1.6.4
7+
- 1.7.4
88
- tip
99

1010
script:

logger.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ package gin
77
import (
88
"fmt"
99
"io"
10+
"os"
1011
"time"
12+
13+
"github.com/mattn/go-isatty"
1114
)
1215

1316
var (
@@ -44,6 +47,12 @@ func Logger() HandlerFunc {
4447
// LoggerWithWriter instance a Logger middleware with the specified writter buffer.
4548
// Example: os.Stdout, a file opened in write mode, a socket...
4649
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
50+
isTerm := true
51+
52+
if w, ok := out.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
53+
isTerm = false
54+
}
55+
4756
var skip map[string]struct{}
4857

4958
if length := len(notlogged); length > 0 {
@@ -71,8 +80,11 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
7180
clientIP := c.ClientIP()
7281
method := c.Request.Method
7382
statusCode := c.Writer.Status()
74-
statusColor := colorForStatus(statusCode)
75-
methodColor := colorForMethod(method)
83+
var statusColor, methodColor string
84+
if isTerm {
85+
statusColor = colorForStatus(statusCode)
86+
methodColor = colorForMethod(method)
87+
}
7688
comment := c.Errors.ByType(ErrorTypePrivate).String()
7789

7890
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s",

0 commit comments

Comments
 (0)