Browse Source

tech: updates log15 vendor packages

Fixes #8262
Daniel Lee 8 years ago
parent
commit
b4cfb225cf

+ 0 - 10
vendor/github.com/inconshreveable/log15/.travis.yml

@@ -1,10 +0,0 @@
-language: go
-
-go:
-  - 1.1
-  - 1.2
-  - 1.3
-  - 1.4
-  - 1.5
-  - 1.6
-  - tip

+ 10 - 3
vendor/github.com/inconshreveable/log15/README.md

@@ -2,7 +2,7 @@
 
 # log15 [![godoc reference](https://godoc.org/github.com/inconshreveable/log15?status.png)](https://godoc.org/github.com/inconshreveable/log15) [![Build Status](https://travis-ci.org/inconshreveable/log15.svg?branch=master)](https://travis-ci.org/inconshreveable/log15)
 
-Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's [`io`](http://golang.org/pkg/io/) and [`net/http`](http://golang.org/pkg/net/http/) packages and is an alternative to the standard library's [`log`](http://golang.org/pkg/log/) package. 
+Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's [`io`](http://golang.org/pkg/io/) and [`net/http`](http://golang.org/pkg/net/http/) packages and is an alternative to the standard library's [`log`](http://golang.org/pkg/log/) package.
 
 ## Features
 - A simple, easy-to-understand API
@@ -30,7 +30,7 @@ import log "github.com/inconshreveable/log15"
 // all loggers can have key/value context
 srvlog := log.New("module", "app/server")
 
-// all log messages can have key/value context 
+// all log messages can have key/value context
 srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
 
 // child loggers with inherited context
@@ -45,7 +45,14 @@ srvlog.SetHandler(log.MultiHandler(
     log.StreamHandler(os.Stderr, log.LogfmtFormat()),
     log.LvlFilterHandler(
         log.LvlError,
-        log.Must.FileHandler("errors.json", log.JsonFormat())))
+        log.Must.FileHandler("errors.json", log.JsonFormat()))))
+```
+
+Will result in output that looks like this:
+
+```
+WARN[06-17|21:58:10] abnormal conn rate                       module=app/server rate=0.500 low=0.100 high=0.800
+INFO[06-17|21:58:10] connection open                          module=app/server raddr=10.0.0.1
 ```
 
 ## Breaking API Changes

+ 2 - 2
vendor/github.com/inconshreveable/log15/doc.go

@@ -97,7 +97,7 @@ context, CallerFileHandler, CallerFuncHandler and CallerStackHandler. Here's
 an example that adds the source file and line number of each logging call to
 the context.
 
-    h := log.CallerFileHandler(log.StdoutHandler())
+    h := log.CallerFileHandler(log.StdoutHandler)
     log.Root().SetHandler(h)
     ...
     log.Error("open file", "err", err)
@@ -108,7 +108,7 @@ This will output a line that looks like:
 
 Here's an example that logs the call stack rather than just the call site.
 
-    h := log.CallerStackHandler("%+v", log.StdoutHandler())
+    h := log.CallerStackHandler("%+v", log.StdoutHandler)
     log.Root().SetHandler(h)
     ...
     log.Error("open file", "err", err)

+ 38 - 16
vendor/github.com/inconshreveable/log15/format.go

@@ -7,6 +7,7 @@ import (
 	"reflect"
 	"strconv"
 	"strings"
+	"sync"
 	"time"
 )
 
@@ -108,7 +109,9 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int) {
 		if color > 0 {
 			fmt.Fprintf(buf, "\x1b[%dm%s\x1b[0m=%s", color, k, v)
 		} else {
-			fmt.Fprintf(buf, "%s=%s", k, v)
+			buf.WriteString(k)
+			buf.WriteByte('=')
+			buf.WriteString(v)
 		}
 	}
 
@@ -205,6 +208,12 @@ func formatLogfmtValue(value interface{}) string {
 		return "nil"
 	}
 
+	if t, ok := value.(time.Time); ok {
+		// Performance optimization: No need for escaping since the provided
+		// timeFormat doesn't have any escape characters, and escaping is
+		// expensive.
+		return t.Format(timeFormat)
+	}
 	value = formatShared(value)
 	switch v := value.(type) {
 	case bool:
@@ -222,36 +231,49 @@ func formatLogfmtValue(value interface{}) string {
 	}
 }
 
+var stringBufPool = sync.Pool{
+	New: func() interface{} { return new(bytes.Buffer) },
+}
+
 func escapeString(s string) string {
-	needQuotes := false
-	e := bytes.Buffer{}
-	e.WriteByte('"')
+	needsQuotes := false
+	needsEscape := false
 	for _, r := range s {
 		if r <= ' ' || r == '=' || r == '"' {
-			needQuotes = true
+			needsQuotes = true
 		}
-
+		if r == '\\' || r == '"' || r == '\n' || r == '\r' || r == '\t' {
+			needsEscape = true
+		}
+	}
+	if needsEscape == false && needsQuotes == false {
+		return s
+	}
+	e := stringBufPool.Get().(*bytes.Buffer)
+	e.WriteByte('"')
+	for _, r := range s {
 		switch r {
 		case '\\', '"':
 			e.WriteByte('\\')
 			e.WriteByte(byte(r))
 		case '\n':
-			e.WriteByte('\\')
-			e.WriteByte('n')
+			e.WriteString("\\n")
 		case '\r':
-			e.WriteByte('\\')
-			e.WriteByte('r')
+			e.WriteString("\\r")
 		case '\t':
-			e.WriteByte('\\')
-			e.WriteByte('t')
+			e.WriteString("\\t")
 		default:
 			e.WriteRune(r)
 		}
 	}
 	e.WriteByte('"')
-	start, stop := 0, e.Len()
-	if !needQuotes {
-		start, stop = 1, stop-1
+	var ret string
+	if needsQuotes {
+		ret = e.String()
+	} else {
+		ret = string(e.Bytes()[1 : e.Len()-1])
 	}
-	return string(e.Bytes()[start:stop])
+	e.Reset()
+	stringBufPool.Put(e)
+	return ret
 }

+ 1 - 1
vendor/github.com/inconshreveable/log15/handler.go

@@ -180,7 +180,7 @@ func MatchFilterHandler(key string, value interface{}, h Handler) Handler {
 // level to the wrapped Handler. For example, to only
 // log Error/Crit records:
 //
-//     log.LvlFilterHandler(log.Error, log.StdoutHandler)
+//     log.LvlFilterHandler(log.LvlError, log.StdoutHandler)
 //
 func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
 	return FilterHandler(func(r *Record) (pass bool) {

+ 1 - 1
vendor/github.com/inconshreveable/log15/syslog.go

@@ -14,7 +14,7 @@ func SyslogHandler(priority syslog.Priority, tag string, fmtr Format) (Handler,
 	return sharedSyslog(fmtr, wr, err)
 }
 
-// SyslogHandler opens a connection to a log daemon over the network and writes
+// SyslogNetHandler opens a connection to a log daemon over the network and writes
 // all log records to it.
 func SyslogNetHandler(net, addr string, priority syslog.Priority, tag string, fmtr Format) (Handler, error) {
 	wr, err := syslog.Dial(net, addr, priority, tag)

+ 1 - 0
vendor/github.com/inconshreveable/log15/term/terminal_darwin.go

@@ -2,6 +2,7 @@
 // Copyright 2013 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
+// +build !appengine
 
 package term
 

+ 7 - 0
vendor/github.com/inconshreveable/log15/term/terminal_netbsd.go

@@ -0,0 +1,7 @@
+package term
+
+import "syscall"
+
+const ioctlReadTermios = syscall.TIOCGETA
+
+type Termios syscall.Termios

+ 1 - 1
vendor/github.com/inconshreveable/log15/term/terminal_notwindows.go

@@ -3,7 +3,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build linux,!appengine darwin freebsd openbsd
+// +build linux,!appengine darwin freebsd openbsd netbsd
 
 package term
 

+ 9 - 0
vendor/github.com/inconshreveable/log15/term/terminal_solaris.go

@@ -0,0 +1,9 @@
+package term
+
+import "golang.org/x/sys/unix"
+
+// IsTty returns true if the given file descriptor is a terminal.
+func IsTty(fd uintptr) bool {
+	_, err := unix.IoctlGetTermios(int(fd), unix.TCGETA)
+	return err == nil
+}

+ 12 - 0
vendor/vendor.json

@@ -416,6 +416,18 @@
 			"revision": "3ab3a8b8831546bd18fd182c20687ca853b2bb13",
 			"revisionTime": "2016-12-15T22:53:35Z"
 		},
+		{
+			"checksumSHA1": "mrmfY0cVu7jvgoIuTRaR8yVVh/M=",
+			"path": "github.com/inconshreveable/log15",
+			"revision": "39bacc234bf1afd0b68573e95b45871f67ba2cd4",
+			"revisionTime": "2017-02-16T22:56:31Z"
+		},
+		{
+			"checksumSHA1": "oVIIInZXKkcRozJfuH2vWJsAS7s=",
+			"path": "github.com/inconshreveable/log15/term",
+			"revision": "39bacc234bf1afd0b68573e95b45871f67ba2cd4",
+			"revisionTime": "2017-02-16T22:56:31Z"
+		},
 		{
 			"checksumSHA1": "BM6ZlNJmtKy3GBoWwg2X55gnZ4A=",
 			"path": "github.com/klauspost/crc32",