Skip to content

Commit

Permalink
v1.1.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	logger.go
  • Loading branch information
javierprovecho committed Dec 4, 2016
2 parents 041ca04 + 18392f5 commit e2212d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package gin
import (
"fmt"
"io"
"os"
"time"

"github.com/mattn/go-isatty"
)

var (
Expand Down Expand Up @@ -44,6 +47,12 @@ 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 w, ok := out.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
isTerm = false
}

var skip map[string]struct{}

if length := len(notlogged); length > 0 {
Expand Down Expand Up @@ -71,8 +80,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",
Expand Down

0 comments on commit e2212d4

Please sign in to comment.