mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 12:59:31 +00:00
``` $ gvt delete github.com/weaveworks/common $ gvt fetch --revision 4d96fd8dcf2c7b417912c6219b310112cb4a4626 github.com/weaveworks/common 2018/07/23 15:31:11 Fetching: github.com/weaveworks/common 2018/07/23 15:31:14 · Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:31:14 · Fetching recursive dependency: github.com/pkg/errors 2018/07/23 15:31:16 · Skipping (existing): github.com/aws/aws-sdk-go/aws 2018/07/23 15:31:16 · Fetching recursive dependency: github.com/sirupsen/logrus 2018/07/23 15:31:18 ·· Skipping (existing): golang.org/x/sys/unix 2018/07/23 15:31:18 ·· Skipping (existing): golang.org/x/crypto/ssh/terminal 2018/07/23 15:31:18 · Skipping (existing): google.golang.org/grpc/status 2018/07/23 15:31:18 · Skipping (existing): github.com/gorilla/mux 2018/07/23 15:31:18 · Fetching recursive dependency: github.com/opentracing-contrib/go-stdlib/nethttp 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:20 · Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:31:20 · Skipping (existing): google.golang.org/grpc 2018/07/23 15:31:20 · Skipping (existing): github.com/pmezard/go-difflib/difflib 2018/07/23 15:31:20 · Fetching recursive dependency: github.com/go-kit/kit/log 2018/07/23 15:31:23 ·· Fetching recursive dependency: github.com/go-logfmt/logfmt 2018/07/23 15:31:25 ··· Fetching recursive dependency: github.com/kr/logfmt 2018/07/23 15:31:27 ·· Fetching recursive dependency: github.com/go-stack/stack 2018/07/23 15:31:29 · Fetching recursive dependency: google.golang.org/genproto/googleapis/rpc/status 2018/07/23 15:31:37 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:37 ·· Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:31:37 · Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:37 · Fetching recursive dependency: github.com/sercand/kuberesolver 2018/07/23 15:31:39 ·· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:31:39 ·· Skipping (existing): google.golang.org/grpc/resolver 2018/07/23 15:31:39 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:39 · Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:31:39 · Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:39 · Skipping (existing): github.com/armon/go-socks5 2018/07/23 15:31:39 · Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:39 · Skipping (existing): github.com/davecgh/go-spew/spew 2018/07/23 15:31:39 · Skipping (existing): github.com/golang/protobuf/ptypes 2018/07/23 15:31:39 · Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:39 · Fetching recursive dependency: github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:41 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:31:41 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/status 2018/07/23 15:31:41 · Fetching recursive dependency: github.com/uber/jaeger-client-go/config 2018/07/23 15:31:44 ·· Fetching recursive dependency: github.com/uber/jaeger-client-go/internal/throttler/remote 2018/07/23 15:31:44 ··· Fetching recursive dependency: github.com/uber/jaeger-client-go/utils 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/agent 2018/07/23 15:31:44 ····· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/jaeger 2018/07/23 15:31:44 ····· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/zipkincore 2018/07/23 15:31:44 ··· Fetching recursive dependency: github.com/uber/jaeger-client-go 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/crossdock/crossdock-go 2018/07/23 15:31:46 ····· Skipping (existing): github.com/davecgh/go-spew/spew 2018/07/23 15:31:46 ····· Skipping (existing): golang.org/x/net/context/ctxhttp 2018/07/23 15:31:46 ····· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:46 ····· Skipping (existing): github.com/pmezard/go-difflib/difflib 2018/07/23 15:31:46 ···· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:46 ···· Fetching recursive dependency: go.uber.org/zap/zapcore 2018/07/23 15:31:49 ····· Fetching recursive dependency: go.uber.org/atomic 2018/07/23 15:31:51 ····· Fetching recursive dependency: go.uber.org/zap/internal/bufferpool 2018/07/23 15:31:51 ······ Fetching recursive dependency: go.uber.org/zap/buffer 2018/07/23 15:31:51 ····· Fetching recursive dependency: go.uber.org/multierr 2018/07/23 15:31:54 ····· Fetching recursive dependency: go.uber.org/zap/internal/exit 2018/07/23 15:31:54 ····· Fetching recursive dependency: go.uber.org/zap/internal/color 2018/07/23 15:31:54 ···· Fetching recursive dependency: go.uber.org/zap 2018/07/23 15:31:54 ···· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:54 ···· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:54 ···· Fetching recursive dependency: github.com/uber/jaeger-lib/metrics 2018/07/23 15:31:56 ····· Fetching recursive dependency: github.com/uber-go/tally 2018/07/23 15:31:58 ······ Fetching recursive dependency: github.com/m3db/prometheus_client_golang/prometheus/promhttp 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/common/expfmt 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/client_model/go 2018/07/23 15:32:00 ······ Fetching recursive dependency: gopkg.in/validator.v2 2018/07/23 15:32:06 ······ Fetching recursive dependency: github.com/cactus/go-statsd-client/statsd 2018/07/23 15:32:08 ······ Skipping (existing): gopkg.in/yaml.v2 2018/07/23 15:32:08 ······ Fetching recursive dependency: github.com/m3db/prometheus_client_golang/prometheus 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/procfs 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/client_model/go 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/common/expfmt 2018/07/23 15:32:08 ······· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:08 ······· Skipping (existing): github.com/beorn7/perks/quantile 2018/07/23 15:32:08 ······· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/common/model 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:08 ······ Fetching recursive dependency: github.com/apache/thrift/lib/go/thrift 2018/07/23 15:32:13 ····· Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:13 ····· Fetching recursive dependency: github.com/go-kit/kit/metrics/influx 2018/07/23 15:32:13 ······ Fetching recursive dependency: github.com/influxdata/influxdb/client/v2 2018/07/23 15:32:17 ······· Fetching recursive dependency: github.com/influxdata/influxdb/models 2018/07/23 15:32:17 ········ Fetching recursive dependency: github.com/influxdata/influxdb/pkg/escape 2018/07/23 15:32:17 ······ Fetching recursive dependency: github.com/go-kit/kit/metrics 2018/07/23 15:32:17 ······· Fetching recursive dependency: github.com/performancecopilot/speed 2018/07/23 15:32:19 ······· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/aws 2018/07/23 15:32:28 ········ Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/internal/sdk 2018/07/23 15:32:28 ········ Skipping (existing): github.com/go-ini/ini 2018/07/23 15:32:28 ········ Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/service/sts 2018/07/23 15:32:28 ········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/private/protocol/query 2018/07/23 15:32:28 ·········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/private/protocol 2018/07/23 15:32:28 ········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/internal/awsutil 2018/07/23 15:32:28 ·········· Skipping (existing): github.com/jmespath/go-jmespath 2018/07/23 15:32:28 ······· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/service/cloudwatch 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/aws 2018/07/23 15:32:29 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/service/cloudwatch 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface 2018/07/23 15:32:29 ······· Fetching recursive dependency: golang.org/x/sync/errgroup 2018/07/23 15:32:31 ········ Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:31 ······· Fetching recursive dependency: github.com/go-kit/kit/util/conn 2018/07/23 15:32:31 ······· Fetching recursive dependency: github.com/VividCortex/gohistogram 2018/07/23 15:32:33 ····· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:33 ····· Fetching recursive dependency: github.com/codahale/hdrhistogram 2018/07/23 15:32:35 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:35 · Fetching recursive dependency: github.com/mwitkow/go-grpc-middleware 2018/07/23 15:32:37 ·· Fetching recursive dependency: github.com/grpc-ecosystem/go-grpc-middleware/logging 2018/07/23 15:32:39 ··· Fetching recursive dependency: github.com/grpc-ecosystem/go-grpc-middleware 2018/07/23 15:32:39 ···· Fetching recursive dependency: github.com/golang/protobuf/jsonpb 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/timestamp 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/duration 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/struct 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/wrappers 2018/07/23 15:32:42 ···· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:32:42 ···· Fetching recursive dependency: github.com/stretchr/testify/suite 2018/07/23 15:32:45 ····· Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:45 ····· Fetching recursive dependency: github.com/stretchr/testify/require 2018/07/23 15:32:45 ······ Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:45 ···· Skipping (existing): google.golang.org/grpc/peer 2018/07/23 15:32:45 ···· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:45 ···· Skipping (existing): golang.org/x/net/trace 2018/07/23 15:32:45 ···· Fetching recursive dependency: github.com/gogo/protobuf/gogoproto 2018/07/23 15:32:48 ····· Fetching recursive dependency: github.com/gogo/protobuf/protoc-gen-gogo/descriptor 2018/07/23 15:32:48 ······ Skipping (existing): github.com/gogo/protobuf/proto 2018/07/23 15:32:48 ····· Skipping (existing): github.com/gogo/protobuf/proto 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/credentials 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ···· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:32:48 ··· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ··· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/peer 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/credentials 2018/07/23 15:32:48 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ·· Skipping (existing): golang.org/x/net/trace 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:32:48 · Fetching recursive dependency: github.com/weaveworks/promrus 2018/07/23 15:32:53 ·· Skipping (existing): gopkg.in/yaml.v2 2018/07/23 15:32:53 ·· Skipping (existing): golang.org/x/net/context/ctxhttp 2018/07/23 15:32:53 ·· Fetching recursive dependency: github.com/stretchr/objx 2018/07/23 15:32:55 ·· Fetching recursive dependency: gopkg.in/alecthomas/kingpin.v2 2018/07/23 15:32:58 ··· Fetching recursive dependency: github.com/alecthomas/units 2018/07/23 15:33:00 ··· Fetching recursive dependency: github.com/alecthomas/template 2018/07/23 15:33:02 ·· Fetching recursive dependency: github.com/julienschmidt/httprouter 2018/07/23 15:33:05 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:33:05 · Skipping (existing): github.com/aws/aws-sdk-go/aws/credentials 2018/07/23 15:33:05 · Skipping (existing): github.com/golang/protobuf/ptypes/empty 2018/07/23 15:33:05 · Skipping (existing): golang.org/x/net/context 2018/07/23 15:33:05 · Skipping (existing): golang.org/x/tools/cover 2018/07/23 15:33:05 · Skipping (existing): github.com/mgutz/ansi ```
311 lines
10 KiB
Go
311 lines
10 KiB
Go
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package zap
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"time"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
// Field is an alias for Field. Aliasing this type dramatically
|
|
// improves the navigability of this package's API documentation.
|
|
type Field = zapcore.Field
|
|
|
|
// Skip constructs a no-op field, which is often useful when handling invalid
|
|
// inputs in other Field constructors.
|
|
func Skip() Field {
|
|
return Field{Type: zapcore.SkipType}
|
|
}
|
|
|
|
// Binary constructs a field that carries an opaque binary blob.
|
|
//
|
|
// Binary data is serialized in an encoding-appropriate format. For example,
|
|
// zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text,
|
|
// use ByteString.
|
|
func Binary(key string, val []byte) Field {
|
|
return Field{Key: key, Type: zapcore.BinaryType, Interface: val}
|
|
}
|
|
|
|
// Bool constructs a field that carries a bool.
|
|
func Bool(key string, val bool) Field {
|
|
var ival int64
|
|
if val {
|
|
ival = 1
|
|
}
|
|
return Field{Key: key, Type: zapcore.BoolType, Integer: ival}
|
|
}
|
|
|
|
// ByteString constructs a field that carries UTF-8 encoded text as a []byte.
|
|
// To log opaque binary blobs (which aren't necessarily valid UTF-8), use
|
|
// Binary.
|
|
func ByteString(key string, val []byte) Field {
|
|
return Field{Key: key, Type: zapcore.ByteStringType, Interface: val}
|
|
}
|
|
|
|
// Complex128 constructs a field that carries a complex number. Unlike most
|
|
// numeric fields, this costs an allocation (to convert the complex128 to
|
|
// interface{}).
|
|
func Complex128(key string, val complex128) Field {
|
|
return Field{Key: key, Type: zapcore.Complex128Type, Interface: val}
|
|
}
|
|
|
|
// Complex64 constructs a field that carries a complex number. Unlike most
|
|
// numeric fields, this costs an allocation (to convert the complex64 to
|
|
// interface{}).
|
|
func Complex64(key string, val complex64) Field {
|
|
return Field{Key: key, Type: zapcore.Complex64Type, Interface: val}
|
|
}
|
|
|
|
// Float64 constructs a field that carries a float64. The way the
|
|
// floating-point value is represented is encoder-dependent, so marshaling is
|
|
// necessarily lazy.
|
|
func Float64(key string, val float64) Field {
|
|
return Field{Key: key, Type: zapcore.Float64Type, Integer: int64(math.Float64bits(val))}
|
|
}
|
|
|
|
// Float32 constructs a field that carries a float32. The way the
|
|
// floating-point value is represented is encoder-dependent, so marshaling is
|
|
// necessarily lazy.
|
|
func Float32(key string, val float32) Field {
|
|
return Field{Key: key, Type: zapcore.Float32Type, Integer: int64(math.Float32bits(val))}
|
|
}
|
|
|
|
// Int constructs a field with the given key and value.
|
|
func Int(key string, val int) Field {
|
|
return Int64(key, int64(val))
|
|
}
|
|
|
|
// Int64 constructs a field with the given key and value.
|
|
func Int64(key string, val int64) Field {
|
|
return Field{Key: key, Type: zapcore.Int64Type, Integer: val}
|
|
}
|
|
|
|
// Int32 constructs a field with the given key and value.
|
|
func Int32(key string, val int32) Field {
|
|
return Field{Key: key, Type: zapcore.Int32Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Int16 constructs a field with the given key and value.
|
|
func Int16(key string, val int16) Field {
|
|
return Field{Key: key, Type: zapcore.Int16Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Int8 constructs a field with the given key and value.
|
|
func Int8(key string, val int8) Field {
|
|
return Field{Key: key, Type: zapcore.Int8Type, Integer: int64(val)}
|
|
}
|
|
|
|
// String constructs a field with the given key and value.
|
|
func String(key string, val string) Field {
|
|
return Field{Key: key, Type: zapcore.StringType, String: val}
|
|
}
|
|
|
|
// Uint constructs a field with the given key and value.
|
|
func Uint(key string, val uint) Field {
|
|
return Uint64(key, uint64(val))
|
|
}
|
|
|
|
// Uint64 constructs a field with the given key and value.
|
|
func Uint64(key string, val uint64) Field {
|
|
return Field{Key: key, Type: zapcore.Uint64Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Uint32 constructs a field with the given key and value.
|
|
func Uint32(key string, val uint32) Field {
|
|
return Field{Key: key, Type: zapcore.Uint32Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Uint16 constructs a field with the given key and value.
|
|
func Uint16(key string, val uint16) Field {
|
|
return Field{Key: key, Type: zapcore.Uint16Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Uint8 constructs a field with the given key and value.
|
|
func Uint8(key string, val uint8) Field {
|
|
return Field{Key: key, Type: zapcore.Uint8Type, Integer: int64(val)}
|
|
}
|
|
|
|
// Uintptr constructs a field with the given key and value.
|
|
func Uintptr(key string, val uintptr) Field {
|
|
return Field{Key: key, Type: zapcore.UintptrType, Integer: int64(val)}
|
|
}
|
|
|
|
// Reflect constructs a field with the given key and an arbitrary object. It uses
|
|
// an encoding-appropriate, reflection-based function to lazily serialize nearly
|
|
// any object into the logging context, but it's relatively slow and
|
|
// allocation-heavy. Outside tests, Any is always a better choice.
|
|
//
|
|
// If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect
|
|
// includes the error message in the final log output.
|
|
func Reflect(key string, val interface{}) Field {
|
|
return Field{Key: key, Type: zapcore.ReflectType, Interface: val}
|
|
}
|
|
|
|
// Namespace creates a named, isolated scope within the logger's context. All
|
|
// subsequent fields will be added to the new namespace.
|
|
//
|
|
// This helps prevent key collisions when injecting loggers into sub-components
|
|
// or third-party libraries.
|
|
func Namespace(key string) Field {
|
|
return Field{Key: key, Type: zapcore.NamespaceType}
|
|
}
|
|
|
|
// Stringer constructs a field with the given key and the output of the value's
|
|
// String method. The Stringer's String method is called lazily.
|
|
func Stringer(key string, val fmt.Stringer) Field {
|
|
return Field{Key: key, Type: zapcore.StringerType, Interface: val}
|
|
}
|
|
|
|
// Time constructs a Field with the given key and value. The encoder
|
|
// controls how the time is serialized.
|
|
func Time(key string, val time.Time) Field {
|
|
return Field{Key: key, Type: zapcore.TimeType, Integer: val.UnixNano(), Interface: val.Location()}
|
|
}
|
|
|
|
// Stack constructs a field that stores a stacktrace of the current goroutine
|
|
// under provided key. Keep in mind that taking a stacktrace is eager and
|
|
// expensive (relatively speaking); this function both makes an allocation and
|
|
// takes about two microseconds.
|
|
func Stack(key string) Field {
|
|
// Returning the stacktrace as a string costs an allocation, but saves us
|
|
// from expanding the zapcore.Field union struct to include a byte slice. Since
|
|
// taking a stacktrace is already so expensive (~10us), the extra allocation
|
|
// is okay.
|
|
return String(key, takeStacktrace())
|
|
}
|
|
|
|
// Duration constructs a field with the given key and value. The encoder
|
|
// controls how the duration is serialized.
|
|
func Duration(key string, val time.Duration) Field {
|
|
return Field{Key: key, Type: zapcore.DurationType, Integer: int64(val)}
|
|
}
|
|
|
|
// Object constructs a field with the given key and ObjectMarshaler. It
|
|
// provides a flexible, but still type-safe and efficient, way to add map- or
|
|
// struct-like user-defined types to the logging context. The struct's
|
|
// MarshalLogObject method is called lazily.
|
|
func Object(key string, val zapcore.ObjectMarshaler) Field {
|
|
return Field{Key: key, Type: zapcore.ObjectMarshalerType, Interface: val}
|
|
}
|
|
|
|
// Any takes a key and an arbitrary value and chooses the best way to represent
|
|
// them as a field, falling back to a reflection-based approach only if
|
|
// necessary.
|
|
//
|
|
// Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between
|
|
// them. To minimize surprises, []byte values are treated as binary blobs, byte
|
|
// values are treated as uint8, and runes are always treated as integers.
|
|
func Any(key string, value interface{}) Field {
|
|
switch val := value.(type) {
|
|
case zapcore.ObjectMarshaler:
|
|
return Object(key, val)
|
|
case zapcore.ArrayMarshaler:
|
|
return Array(key, val)
|
|
case bool:
|
|
return Bool(key, val)
|
|
case []bool:
|
|
return Bools(key, val)
|
|
case complex128:
|
|
return Complex128(key, val)
|
|
case []complex128:
|
|
return Complex128s(key, val)
|
|
case complex64:
|
|
return Complex64(key, val)
|
|
case []complex64:
|
|
return Complex64s(key, val)
|
|
case float64:
|
|
return Float64(key, val)
|
|
case []float64:
|
|
return Float64s(key, val)
|
|
case float32:
|
|
return Float32(key, val)
|
|
case []float32:
|
|
return Float32s(key, val)
|
|
case int:
|
|
return Int(key, val)
|
|
case []int:
|
|
return Ints(key, val)
|
|
case int64:
|
|
return Int64(key, val)
|
|
case []int64:
|
|
return Int64s(key, val)
|
|
case int32:
|
|
return Int32(key, val)
|
|
case []int32:
|
|
return Int32s(key, val)
|
|
case int16:
|
|
return Int16(key, val)
|
|
case []int16:
|
|
return Int16s(key, val)
|
|
case int8:
|
|
return Int8(key, val)
|
|
case []int8:
|
|
return Int8s(key, val)
|
|
case string:
|
|
return String(key, val)
|
|
case []string:
|
|
return Strings(key, val)
|
|
case uint:
|
|
return Uint(key, val)
|
|
case []uint:
|
|
return Uints(key, val)
|
|
case uint64:
|
|
return Uint64(key, val)
|
|
case []uint64:
|
|
return Uint64s(key, val)
|
|
case uint32:
|
|
return Uint32(key, val)
|
|
case []uint32:
|
|
return Uint32s(key, val)
|
|
case uint16:
|
|
return Uint16(key, val)
|
|
case []uint16:
|
|
return Uint16s(key, val)
|
|
case uint8:
|
|
return Uint8(key, val)
|
|
case []byte:
|
|
return Binary(key, val)
|
|
case uintptr:
|
|
return Uintptr(key, val)
|
|
case []uintptr:
|
|
return Uintptrs(key, val)
|
|
case time.Time:
|
|
return Time(key, val)
|
|
case []time.Time:
|
|
return Times(key, val)
|
|
case time.Duration:
|
|
return Duration(key, val)
|
|
case []time.Duration:
|
|
return Durations(key, val)
|
|
case error:
|
|
return NamedError(key, val)
|
|
case []error:
|
|
return Errors(key, val)
|
|
case fmt.Stringer:
|
|
return Stringer(key, val)
|
|
default:
|
|
return Reflect(key, val)
|
|
}
|
|
}
|