Skip to content
Myr

v1.1.4

Before adoption: this commit came in with the history the project adopted, so no landing records it.

# Conflicts: # logger.go

authored by Javier Provecho Fernandez · committed by Javier Provecho Fernandez · parents 041ca04, 18392f5 · Browse files · 2 files+17 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−5 removed

  • other:+17 added−5 removed

2 files+17 added−5 removed

modified:.travis.yml+3 added-3 removed
modified:logger.go+14 added-2 removed
5 unmodified lines
67import (8 "fmt"9 "io"10 "os"11 "time"1213 "github.com/mattn/go-isatty"14)1516var (17 green = string([]byte{27, 91, 57, 55, 59, 52, 50, 109})
28 unmodified lines
4647// LoggerWithWriter instance a Logger middleware with the specified writter buffer.48// Example: os.Stdout, a file opened in write mode, a socket...49func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {50 isTerm := true5152 if w, ok := out.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {53 isTerm = false54 }5556 var skip map[string]struct{}5758 if length := len(notlogged); length > 0 {59 skip = make(map[string]struct{}, length)
19 unmodified lines
7980 clientIP := c.ClientIP()81 method := c.Request.Method82 statusCode := c.Writer.Status()83 var statusColor, methodColor string84 if isTerm {74 statusColor := colorForStatus(statusCode)75 methodColor := colorForMethod(method)85 statusColor = colorForStatus(statusCode)86 methodColor = colorForMethod(method)87 }88 comment := c.Errors.ByType(ErrorTypePrivate).String()8990 fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s",91 end.Format("2006/01/02 - 15:04:05"),
44 unmodified lines