tech: updates log15 vendor packages

Fixes #8262
This commit is contained in:
Daniel Lee 2017-05-02 12:47:32 +02:00
parent ac6c93b3da
commit b4cfb225cf
11 changed files with 82 additions and 34 deletions

View File

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

View File

@ -45,7 +45,14 @@ srvlog.SetHandler(log.MultiHandler(
log.StreamHandler(os.Stderr, log.LogfmtFormat()), log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler( log.LvlFilterHandler(
log.LvlError, 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 ## Breaking API Changes

View File

@ -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 an example that adds the source file and line number of each logging call to
the context. the context.
h := log.CallerFileHandler(log.StdoutHandler()) h := log.CallerFileHandler(log.StdoutHandler)
log.Root().SetHandler(h) log.Root().SetHandler(h)
... ...
log.Error("open file", "err", err) 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. 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.Root().SetHandler(h)
... ...
log.Error("open file", "err", err) log.Error("open file", "err", err)

View File

@ -7,6 +7,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
) )
@ -108,7 +109,9 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int) {
if color > 0 { if color > 0 {
fmt.Fprintf(buf, "\x1b[%dm%s\x1b[0m=%s", color, k, v) fmt.Fprintf(buf, "\x1b[%dm%s\x1b[0m=%s", color, k, v)
} else { } 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" 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) value = formatShared(value)
switch v := value.(type) { switch v := value.(type) {
case bool: 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 { func escapeString(s string) string {
needQuotes := false needsQuotes := false
e := bytes.Buffer{} needsEscape := false
e.WriteByte('"')
for _, r := range s { for _, r := range s {
if r <= ' ' || r == '=' || r == '"' { 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 { switch r {
case '\\', '"': case '\\', '"':
e.WriteByte('\\') e.WriteByte('\\')
e.WriteByte(byte(r)) e.WriteByte(byte(r))
case '\n': case '\n':
e.WriteByte('\\') e.WriteString("\\n")
e.WriteByte('n')
case '\r': case '\r':
e.WriteByte('\\') e.WriteString("\\r")
e.WriteByte('r')
case '\t': case '\t':
e.WriteByte('\\') e.WriteString("\\t")
e.WriteByte('t')
default: default:
e.WriteRune(r) e.WriteRune(r)
} }
} }
e.WriteByte('"') e.WriteByte('"')
start, stop := 0, e.Len() var ret string
if !needQuotes { if needsQuotes {
start, stop = 1, stop-1 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
} }

View File

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

View File

@ -14,7 +14,7 @@ func SyslogHandler(priority syslog.Priority, tag string, fmtr Format) (Handler,
return sharedSyslog(fmtr, wr, err) 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. // all log records to it.
func SyslogNetHandler(net, addr string, priority syslog.Priority, tag string, fmtr Format) (Handler, error) { func SyslogNetHandler(net, addr string, priority syslog.Priority, tag string, fmtr Format) (Handler, error) {
wr, err := syslog.Dial(net, addr, priority, tag) wr, err := syslog.Dial(net, addr, priority, tag)

View File

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

View File

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

View File

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

View File

@ -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
vendor/vendor.json vendored
View File

@ -416,6 +416,18 @@
"revision": "3ab3a8b8831546bd18fd182c20687ca853b2bb13", "revision": "3ab3a8b8831546bd18fd182c20687ca853b2bb13",
"revisionTime": "2016-12-15T22:53:35Z" "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=", "checksumSHA1": "BM6ZlNJmtKy3GBoWwg2X55gnZ4A=",
"path": "github.com/klauspost/crc32", "path": "github.com/klauspost/crc32",