Revert "Merge pull request #744 from aviddiviner/logger-fix"

This reverts commit c3bfd69303, reversing
changes made to 9177f01c28.
This commit is contained in:
Javier Provecho Fernandez 2016-12-03 22:03:39 +01:00
parent 6f474cb42d
commit 19f271c86b

View File

@ -7,10 +7,7 @@ package gin
import ( import (
"fmt" "fmt"
"io" "io"
"os"
"time" "time"
"golang.org/x/crypto/ssh/terminal"
) )
var ( var (
@ -47,11 +44,6 @@ func Logger() HandlerFunc {
// LoggerWithWriter instance a Logger middleware with the specified writter buffer. // LoggerWithWriter instance a Logger middleware with the specified writter buffer.
// Example: os.Stdout, a file opened in write mode, a socket... // Example: os.Stdout, a file opened in write mode, a socket...
func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc { 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{} var skip map[string]struct{}
if length := len(notlogged); length > 0 { if length := len(notlogged); length > 0 {
@ -79,11 +71,8 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
clientIP := c.ClientIP() clientIP := c.ClientIP()
method := c.Request.Method method := c.Request.Method
statusCode := c.Writer.Status() statusCode := c.Writer.Status()
var statusColor, methodColor string statusColor := colorForStatus(statusCode)
if isTerm { methodColor := colorForMethod(method)
statusColor = colorForStatus(statusCode)
methodColor = colorForMethod(method)
}
comment := c.Errors.ByType(ErrorTypePrivate).String() comment := c.Errors.ByType(ErrorTypePrivate).String()
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s", fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %s |%s %s %-7s %s\n%s",