build: upgrade dependency and build with go 1.21
This commit is contained in:
34
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
34
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
@ -3,6 +3,40 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.25.0 (1 Aug 2023)
|
||||
|
||||
This release contains several improvements including performance, API additions,
|
||||
and two new experimental packages whose APIs are unstable and may change in the
|
||||
future.
|
||||
|
||||
Enhancements:
|
||||
* [#1246][]: Add `zap/exp/zapslog` package for integration with slog.
|
||||
* [#1273][]: Add `Name` to `Logger` which returns the Logger's name if one is set.
|
||||
* [#1281][]: Add `zap/exp/expfield` package which contains helper methods
|
||||
`Str` and `Strs` for constructing String-like zap.Fields.
|
||||
* [#1310][]: Reduce stack size on `Any`.
|
||||
|
||||
Thanks to @knight42, @dzakaammar, @bcspragu, and @rexywork for their contributions
|
||||
to this release.
|
||||
|
||||
[#1246]: https://github.com/uber-go/zap/pull/1246
|
||||
[#1273]: https://github.com/uber-go/zap/pull/1273
|
||||
[#1281]: https://github.com/uber-go/zap/pull/1281
|
||||
[#1310]: https://github.com/uber-go/zap/pull/1310
|
||||
|
||||
## 1.24.0 (30 Nov 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1148][]: Add `Level` to both `Logger` and `SugaredLogger` that reports the
|
||||
current minimum enabled log level.
|
||||
* [#1185][]: `SugaredLogger` turns errors to zap.Error automatically.
|
||||
|
||||
Thanks to @Abirdcfly, @craigpastro, @nnnkkk7, and @sashamelentyev for their
|
||||
contributions to this release.
|
||||
|
||||
[#1148]: https://github.coml/uber-go/zap/pull/1148
|
||||
[#1185]: https://github.coml/uber-go/zap/pull/1185
|
||||
|
||||
## 1.23.0 (24 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
|
21
vendor/go.uber.org/zap/Makefile
generated
vendored
21
vendor/go.uber.org/zap/Makefile
generated
vendored
@ -1,13 +1,14 @@
|
||||
export GOBIN ?= $(shell pwd)/bin
|
||||
|
||||
GOLINT = $(GOBIN)/golint
|
||||
REVIVE = $(GOBIN)/revive
|
||||
STATICCHECK = $(GOBIN)/staticcheck
|
||||
GOVULNCHECK = $(GOBIN)/govulncheck
|
||||
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
|
||||
|
||||
# Directories containing independent Go modules.
|
||||
#
|
||||
# We track coverage only for the main module.
|
||||
MODULE_DIRS = . ./benchmarks ./zapgrpc/internal/test
|
||||
MODULE_DIRS = . ./exp ./benchmarks ./zapgrpc/internal/test
|
||||
|
||||
# Many Go tools take file globs or directories as arguments instead of packages.
|
||||
GO_FILES := $(shell \
|
||||
@ -18,14 +19,15 @@ GO_FILES := $(shell \
|
||||
all: lint test
|
||||
|
||||
.PHONY: lint
|
||||
lint: $(GOLINT) $(STATICCHECK)
|
||||
lint: $(REVIVE) $(STATICCHECK)
|
||||
@rm -rf lint.log
|
||||
@echo "Checking formatting..."
|
||||
@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
|
||||
@echo "Checking vet..."
|
||||
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
|
||||
@echo "Checking lint..."
|
||||
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
|
||||
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && \
|
||||
$(REVIVE) -set_exit_status ./... 2>&1) &&) true | tee -a lint.log
|
||||
@echo "Checking staticcheck..."
|
||||
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(STATICCHECK) ./... 2>&1) &&) true | tee -a lint.log
|
||||
@echo "Checking for unresolved FIXMEs..."
|
||||
@ -40,8 +42,11 @@ lint: $(GOLINT) $(STATICCHECK)
|
||||
git --no-pager diff; \
|
||||
fi
|
||||
|
||||
$(GOLINT):
|
||||
cd tools && go install golang.org/x/lint/golint
|
||||
$(REVIVE):
|
||||
cd tools && go install github.com/mgechev/revive
|
||||
|
||||
$(GOVULNCHECK):
|
||||
cd tools && go install golang.org/x/vuln/cmd/govulncheck
|
||||
|
||||
$(STATICCHECK):
|
||||
cd tools && go install honnef.co/go/tools/cmd/staticcheck
|
||||
@ -71,3 +76,7 @@ updatereadme:
|
||||
.PHONY: tidy
|
||||
tidy:
|
||||
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true
|
||||
|
||||
.PHONY: vulncheck
|
||||
vulncheck: $(GOVULNCHECK)
|
||||
$(GOVULNCHECK) ./...
|
62
vendor/go.uber.org/zap/README.md
generated
vendored
62
vendor/go.uber.org/zap/README.md
generated
vendored
@ -54,7 +54,7 @@ and make many small allocations. Put differently, using `encoding/json` and
|
||||
Zap takes a different approach. It includes a reflection-free, zero-allocation
|
||||
JSON encoder, and the base `Logger` strives to avoid serialization overhead
|
||||
and allocations wherever possible. By building the high-level `SugaredLogger`
|
||||
on that foundation, zap lets users _choose_ when they need to count every
|
||||
on that foundation, zap lets users *choose* when they need to count every
|
||||
allocation and when they'd prefer a more familiar, loosely typed API.
|
||||
|
||||
As measured by its own [benchmarking suite][], not only is zap more performant
|
||||
@ -64,40 +64,43 @@ id="anchor-versions">[1](#footnote-versions)</sup>
|
||||
|
||||
Log a message and 10 fields:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :---------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 2900 ns/op | +0% | 5 allocs/op |
|
||||
| :zap: zap (sugared) | 3475 ns/op | +20% | 10 allocs/op |
|
||||
| zerolog | 10639 ns/op | +267% | 32 allocs/op |
|
||||
| go-kit | 14434 ns/op | +398% | 59 allocs/op |
|
||||
| logrus | 17104 ns/op | +490% | 81 allocs/op |
|
||||
| apex/log | 32424 ns/op | +1018% | 66 allocs/op |
|
||||
| log15 | 33579 ns/op | +1058% | 76 allocs/op |
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 1744 ns/op | +0% | 5 allocs/op
|
||||
| :zap: zap (sugared) | 2483 ns/op | +42% | 10 allocs/op
|
||||
| zerolog | 918 ns/op | -47% | 1 allocs/op
|
||||
| go-kit | 5590 ns/op | +221% | 57 allocs/op
|
||||
| slog | 5640 ns/op | +223% | 40 allocs/op
|
||||
| apex/log | 21184 ns/op | +1115% | 63 allocs/op
|
||||
| logrus | 24338 ns/op | +1296% | 79 allocs/op
|
||||
| log15 | 26054 ns/op | +1394% | 74 allocs/op
|
||||
|
||||
Log a message with a logger that already has 10 fields of context:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :---------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 373 ns/op | +0% | 0 allocs/op |
|
||||
| :zap: zap (sugared) | 452 ns/op | +21% | 1 allocs/op |
|
||||
| zerolog | 288 ns/op | -23% | 0 allocs/op |
|
||||
| go-kit | 11785 ns/op | +3060% | 58 allocs/op |
|
||||
| logrus | 19629 ns/op | +5162% | 70 allocs/op |
|
||||
| log15 | 21866 ns/op | +5762% | 72 allocs/op |
|
||||
| apex/log | 30890 ns/op | +8182% | 55 allocs/op |
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 193 ns/op | +0% | 0 allocs/op
|
||||
| :zap: zap (sugared) | 227 ns/op | +18% | 1 allocs/op
|
||||
| zerolog | 81 ns/op | -58% | 0 allocs/op
|
||||
| slog | 322 ns/op | +67% | 0 allocs/op
|
||||
| go-kit | 5377 ns/op | +2686% | 56 allocs/op
|
||||
| apex/log | 19518 ns/op | +10013% | 53 allocs/op
|
||||
| log15 | 19812 ns/op | +10165% | 70 allocs/op
|
||||
| logrus | 21997 ns/op | +11297% | 68 allocs/op
|
||||
|
||||
Log a static string, without any context or `printf`-style templating:
|
||||
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------------------ | :--------: | :-----------: | :---------------: |
|
||||
| :zap: zap | 381 ns/op | +0% | 0 allocs/op |
|
||||
| :zap: zap (sugared) | 410 ns/op | +8% | 1 allocs/op |
|
||||
| zerolog | 369 ns/op | -3% | 0 allocs/op |
|
||||
| standard library | 385 ns/op | +1% | 2 allocs/op |
|
||||
| go-kit | 606 ns/op | +59% | 11 allocs/op |
|
||||
| logrus | 1730 ns/op | +354% | 25 allocs/op |
|
||||
| apex/log | 1998 ns/op | +424% | 7 allocs/op |
|
||||
| log15 | 4546 ns/op | +1093% | 22 allocs/op |
|
||||
| Package | Time | Time % to zap | Objects Allocated |
|
||||
| :------ | :--: | :-----------: | :---------------: |
|
||||
| :zap: zap | 165 ns/op | +0% | 0 allocs/op
|
||||
| :zap: zap (sugared) | 212 ns/op | +28% | 1 allocs/op
|
||||
| zerolog | 95 ns/op | -42% | 0 allocs/op
|
||||
| slog | 296 ns/op | +79% | 0 allocs/op
|
||||
| go-kit | 415 ns/op | +152% | 9 allocs/op
|
||||
| standard library | 422 ns/op | +156% | 2 allocs/op
|
||||
| apex/log | 1601 ns/op | +870% | 5 allocs/op
|
||||
| logrus | 3017 ns/op | +1728% | 23 allocs/op
|
||||
| log15 | 3469 ns/op | +2002% | 20 allocs/op
|
||||
|
||||
## Development Status: Stable
|
||||
|
||||
@ -131,3 +134,4 @@ pinned in the [benchmarks/go.mod][] file. [↩](#anchor-versions)
|
||||
[cov]: https://codecov.io/gh/uber-go/zap
|
||||
[benchmarking suite]: https://github.com/uber-go/zap/tree/master/benchmarks
|
||||
[benchmarks/go.mod]: https://github.com/uber-go/zap/blob/master/benchmarks/go.mod
|
||||
|
||||
|
8
vendor/go.uber.org/zap/array_go118.go
generated
vendored
8
vendor/go.uber.org/zap/array_go118.go
generated
vendored
@ -76,9 +76,9 @@ func (os objects[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// objectMarshalerPtr is a constraint that specifies that the given type
|
||||
// ObjectMarshalerPtr is a constraint that specifies that the given type
|
||||
// implements zapcore.ObjectMarshaler on a pointer receiver.
|
||||
type objectMarshalerPtr[T any] interface {
|
||||
type ObjectMarshalerPtr[T any] interface {
|
||||
*T
|
||||
zapcore.ObjectMarshaler
|
||||
}
|
||||
@ -105,11 +105,11 @@ type objectMarshalerPtr[T any] interface {
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
func ObjectValues[T any, P objectMarshalerPtr[T]](key string, values []T) Field {
|
||||
func ObjectValues[T any, P ObjectMarshalerPtr[T]](key string, values []T) Field {
|
||||
return Array(key, objectValues[T, P](values))
|
||||
}
|
||||
|
||||
type objectValues[T any, P objectMarshalerPtr[T]] []T
|
||||
type objectValues[T any, P ObjectMarshalerPtr[T]] []T
|
||||
|
||||
func (os objectValues[T, P]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for i := range os {
|
||||
|
20
vendor/go.uber.org/zap/buffer/pool.go
generated
vendored
20
vendor/go.uber.org/zap/buffer/pool.go
generated
vendored
@ -20,25 +20,29 @@
|
||||
|
||||
package buffer
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
// A Pool is a type-safe wrapper around a sync.Pool.
|
||||
type Pool struct {
|
||||
p *sync.Pool
|
||||
p *pool.Pool[*Buffer]
|
||||
}
|
||||
|
||||
// NewPool constructs a new Pool.
|
||||
func NewPool() Pool {
|
||||
return Pool{p: &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &Buffer{bs: make([]byte, 0, _size)}
|
||||
},
|
||||
}}
|
||||
return Pool{
|
||||
p: pool.New(func() *Buffer {
|
||||
return &Buffer{
|
||||
bs: make([]byte, 0, _size),
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Get retrieves a Buffer from the pool, creating one if necessary.
|
||||
func (p Pool) Get() *Buffer {
|
||||
buf := p.p.Get().(*Buffer)
|
||||
buf := p.p.Get()
|
||||
buf.Reset()
|
||||
buf.pool = p
|
||||
return buf
|
||||
|
84
vendor/go.uber.org/zap/config.go
generated
vendored
84
vendor/go.uber.org/zap/config.go
generated
vendored
@ -95,6 +95,32 @@ type Config struct {
|
||||
|
||||
// NewProductionEncoderConfig returns an opinionated EncoderConfig for
|
||||
// production environments.
|
||||
//
|
||||
// Messages encoded with this configuration will be JSON-formatted
|
||||
// and will have the following keys by default:
|
||||
//
|
||||
// - "level": The logging level (e.g. "info", "error").
|
||||
// - "ts": The current time in number of seconds since the Unix epoch.
|
||||
// - "msg": The message passed to the log statement.
|
||||
// - "caller": If available, a short path to the file and line number
|
||||
// where the log statement was issued.
|
||||
// The logger configuration determines whether this field is captured.
|
||||
// - "stacktrace": If available, a stack trace from the line
|
||||
// where the log statement was issued.
|
||||
// The logger configuration determines whether this field is captured.
|
||||
//
|
||||
// By default, the following formats are used for different types:
|
||||
//
|
||||
// - Time is formatted as floating-point number of seconds since the Unix
|
||||
// epoch.
|
||||
// - Duration is formatted as floating-point number of seconds.
|
||||
//
|
||||
// You may change these by setting the appropriate fields in the returned
|
||||
// object.
|
||||
// For example, use the following to change the time encoding format:
|
||||
//
|
||||
// cfg := zap.NewProductionEncoderConfig()
|
||||
// cfg.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
func NewProductionEncoderConfig() zapcore.EncoderConfig {
|
||||
return zapcore.EncoderConfig{
|
||||
TimeKey: "ts",
|
||||
@ -112,11 +138,22 @@ func NewProductionEncoderConfig() zapcore.EncoderConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// NewProductionConfig is a reasonable production logging configuration.
|
||||
// Logging is enabled at InfoLevel and above.
|
||||
// NewProductionConfig builds a reasonable default production logging
|
||||
// configuration.
|
||||
// Logging is enabled at InfoLevel and above, and uses a JSON encoder.
|
||||
// Logs are written to standard error.
|
||||
// Stacktraces are included on logs of ErrorLevel and above.
|
||||
// DPanicLevel logs will not panic, but will write a stacktrace.
|
||||
//
|
||||
// It uses a JSON encoder, writes to standard error, and enables sampling.
|
||||
// Stacktraces are automatically included on logs of ErrorLevel and above.
|
||||
// Sampling is enabled at 100:100 by default,
|
||||
// meaning that after the first 100 log entries
|
||||
// with the same level and message in the same second,
|
||||
// it will log every 100th entry
|
||||
// with the same level and message in the same second.
|
||||
// You may disable this behavior by setting Sampling to nil.
|
||||
//
|
||||
// See [NewProductionEncoderConfig] for information
|
||||
// on the default encoder configuration.
|
||||
func NewProductionConfig() Config {
|
||||
return Config{
|
||||
Level: NewAtomicLevelAt(InfoLevel),
|
||||
@ -134,6 +171,32 @@ func NewProductionConfig() Config {
|
||||
|
||||
// NewDevelopmentEncoderConfig returns an opinionated EncoderConfig for
|
||||
// development environments.
|
||||
//
|
||||
// Messages encoded with this configuration will use Zap's console encoder
|
||||
// intended to print human-readable output.
|
||||
// It will print log messages with the following information:
|
||||
//
|
||||
// - The log level (e.g. "INFO", "ERROR").
|
||||
// - The time in ISO8601 format (e.g. "2017-01-01T12:00:00Z").
|
||||
// - The message passed to the log statement.
|
||||
// - If available, a short path to the file and line number
|
||||
// where the log statement was issued.
|
||||
// The logger configuration determines whether this field is captured.
|
||||
// - If available, a stacktrace from the line
|
||||
// where the log statement was issued.
|
||||
// The logger configuration determines whether this field is captured.
|
||||
//
|
||||
// By default, the following formats are used for different types:
|
||||
//
|
||||
// - Time is formatted in ISO8601 format (e.g. "2017-01-01T12:00:00Z").
|
||||
// - Duration is formatted as a string (e.g. "1.234s").
|
||||
//
|
||||
// You may change these by setting the appropriate fields in the returned
|
||||
// object.
|
||||
// For example, use the following to change the time encoding format:
|
||||
//
|
||||
// cfg := zap.NewDevelopmentEncoderConfig()
|
||||
// cfg.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
func NewDevelopmentEncoderConfig() zapcore.EncoderConfig {
|
||||
return zapcore.EncoderConfig{
|
||||
// Keys can be anything except the empty string.
|
||||
@ -152,12 +215,15 @@ func NewDevelopmentEncoderConfig() zapcore.EncoderConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// NewDevelopmentConfig is a reasonable development logging configuration.
|
||||
// Logging is enabled at DebugLevel and above.
|
||||
// NewDevelopmentConfig builds a reasonable default development logging
|
||||
// configuration.
|
||||
// Logging is enabled at DebugLevel and above, and uses a console encoder.
|
||||
// Logs are written to standard error.
|
||||
// Stacktraces are included on logs of WarnLevel and above.
|
||||
// DPanicLevel logs will panic.
|
||||
//
|
||||
// It enables development mode (which makes DPanicLevel logs panic), uses a
|
||||
// console encoder, writes to standard error, and disables sampling.
|
||||
// Stacktraces are automatically included on logs of WarnLevel and above.
|
||||
// See [NewDevelopmentEncoderConfig] for information
|
||||
// on the default encoder configuration.
|
||||
func NewDevelopmentConfig() Config {
|
||||
return Config{
|
||||
Level: NewAtomicLevelAt(DebugLevel),
|
||||
|
9
vendor/go.uber.org/zap/error.go
generated
vendored
9
vendor/go.uber.org/zap/error.go
generated
vendored
@ -21,14 +21,13 @@
|
||||
package zap
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap/internal/pool"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var _errArrayElemPool = sync.Pool{New: func() interface{} {
|
||||
var _errArrayElemPool = pool.New(func() *errArrayElem {
|
||||
return &errArrayElem{}
|
||||
}}
|
||||
})
|
||||
|
||||
// Error is shorthand for the common idiom NamedError("error", err).
|
||||
func Error(err error) Field {
|
||||
@ -60,7 +59,7 @@ func (errs errArray) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
// potentially an "errorVerbose" attribute, we need to wrap it in a
|
||||
// type that implements LogObjectMarshaler. To prevent this from
|
||||
// allocating, pool the wrapper type.
|
||||
elem := _errArrayElemPool.Get().(*errArrayElem)
|
||||
elem := _errArrayElemPool.Get()
|
||||
elem.error = errs[i]
|
||||
arr.AppendObject(elem)
|
||||
elem.error = nil
|
||||
|
169
vendor/go.uber.org/zap/field.go
generated
vendored
169
vendor/go.uber.org/zap/field.go
generated
vendored
@ -410,6 +410,43 @@ func Inline(val zapcore.ObjectMarshaler) Field {
|
||||
}
|
||||
}
|
||||
|
||||
// We discovered an issue where zap.Any can cause a performance degradation
|
||||
// when used in new goroutines.
|
||||
//
|
||||
// This happens because the compiler assigns 4.8kb (one zap.Field per arm of
|
||||
// switch statement) of stack space for zap.Any when it takes the form:
|
||||
//
|
||||
// switch v := v.(type) {
|
||||
// case string:
|
||||
// return String(key, v)
|
||||
// case int:
|
||||
// return Int(key, v)
|
||||
// // ...
|
||||
// default:
|
||||
// return Reflect(key, v)
|
||||
// }
|
||||
//
|
||||
// To avoid this, we use the type switch to assign a value to a single local variable
|
||||
// and then call a function on it.
|
||||
// The local variable is just a function reference so it doesn't allocate
|
||||
// when converted to an interface{}.
|
||||
//
|
||||
// A fair bit of experimentation went into this.
|
||||
// See also:
|
||||
//
|
||||
// - https://github.com/uber-go/zap/pull/1301
|
||||
// - https://github.com/uber-go/zap/pull/1303
|
||||
// - https://github.com/uber-go/zap/pull/1304
|
||||
// - https://github.com/uber-go/zap/pull/1305
|
||||
// - https://github.com/uber-go/zap/pull/1308
|
||||
type anyFieldC[T any] func(string, T) Field
|
||||
|
||||
func (f anyFieldC[T]) Any(key string, val any) Field {
|
||||
v, _ := val.(T)
|
||||
// val is guaranteed to be a T, except when it's nil.
|
||||
return f(key, v)
|
||||
}
|
||||
|
||||
// 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.
|
||||
@ -418,132 +455,136 @@ func Inline(val zapcore.ObjectMarshaler) Field {
|
||||
// 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) {
|
||||
var c interface{ Any(string, any) Field }
|
||||
|
||||
switch value.(type) {
|
||||
case zapcore.ObjectMarshaler:
|
||||
return Object(key, val)
|
||||
c = anyFieldC[zapcore.ObjectMarshaler](Object)
|
||||
case zapcore.ArrayMarshaler:
|
||||
return Array(key, val)
|
||||
c = anyFieldC[zapcore.ArrayMarshaler](Array)
|
||||
case bool:
|
||||
return Bool(key, val)
|
||||
c = anyFieldC[bool](Bool)
|
||||
case *bool:
|
||||
return Boolp(key, val)
|
||||
c = anyFieldC[*bool](Boolp)
|
||||
case []bool:
|
||||
return Bools(key, val)
|
||||
c = anyFieldC[[]bool](Bools)
|
||||
case complex128:
|
||||
return Complex128(key, val)
|
||||
c = anyFieldC[complex128](Complex128)
|
||||
case *complex128:
|
||||
return Complex128p(key, val)
|
||||
c = anyFieldC[*complex128](Complex128p)
|
||||
case []complex128:
|
||||
return Complex128s(key, val)
|
||||
c = anyFieldC[[]complex128](Complex128s)
|
||||
case complex64:
|
||||
return Complex64(key, val)
|
||||
c = anyFieldC[complex64](Complex64)
|
||||
case *complex64:
|
||||
return Complex64p(key, val)
|
||||
c = anyFieldC[*complex64](Complex64p)
|
||||
case []complex64:
|
||||
return Complex64s(key, val)
|
||||
c = anyFieldC[[]complex64](Complex64s)
|
||||
case float64:
|
||||
return Float64(key, val)
|
||||
c = anyFieldC[float64](Float64)
|
||||
case *float64:
|
||||
return Float64p(key, val)
|
||||
c = anyFieldC[*float64](Float64p)
|
||||
case []float64:
|
||||
return Float64s(key, val)
|
||||
c = anyFieldC[[]float64](Float64s)
|
||||
case float32:
|
||||
return Float32(key, val)
|
||||
c = anyFieldC[float32](Float32)
|
||||
case *float32:
|
||||
return Float32p(key, val)
|
||||
c = anyFieldC[*float32](Float32p)
|
||||
case []float32:
|
||||
return Float32s(key, val)
|
||||
c = anyFieldC[[]float32](Float32s)
|
||||
case int:
|
||||
return Int(key, val)
|
||||
c = anyFieldC[int](Int)
|
||||
case *int:
|
||||
return Intp(key, val)
|
||||
c = anyFieldC[*int](Intp)
|
||||
case []int:
|
||||
return Ints(key, val)
|
||||
c = anyFieldC[[]int](Ints)
|
||||
case int64:
|
||||
return Int64(key, val)
|
||||
c = anyFieldC[int64](Int64)
|
||||
case *int64:
|
||||
return Int64p(key, val)
|
||||
c = anyFieldC[*int64](Int64p)
|
||||
case []int64:
|
||||
return Int64s(key, val)
|
||||
c = anyFieldC[[]int64](Int64s)
|
||||
case int32:
|
||||
return Int32(key, val)
|
||||
c = anyFieldC[int32](Int32)
|
||||
case *int32:
|
||||
return Int32p(key, val)
|
||||
c = anyFieldC[*int32](Int32p)
|
||||
case []int32:
|
||||
return Int32s(key, val)
|
||||
c = anyFieldC[[]int32](Int32s)
|
||||
case int16:
|
||||
return Int16(key, val)
|
||||
c = anyFieldC[int16](Int16)
|
||||
case *int16:
|
||||
return Int16p(key, val)
|
||||
c = anyFieldC[*int16](Int16p)
|
||||
case []int16:
|
||||
return Int16s(key, val)
|
||||
c = anyFieldC[[]int16](Int16s)
|
||||
case int8:
|
||||
return Int8(key, val)
|
||||
c = anyFieldC[int8](Int8)
|
||||
case *int8:
|
||||
return Int8p(key, val)
|
||||
c = anyFieldC[*int8](Int8p)
|
||||
case []int8:
|
||||
return Int8s(key, val)
|
||||
c = anyFieldC[[]int8](Int8s)
|
||||
case string:
|
||||
return String(key, val)
|
||||
c = anyFieldC[string](String)
|
||||
case *string:
|
||||
return Stringp(key, val)
|
||||
c = anyFieldC[*string](Stringp)
|
||||
case []string:
|
||||
return Strings(key, val)
|
||||
c = anyFieldC[[]string](Strings)
|
||||
case uint:
|
||||
return Uint(key, val)
|
||||
c = anyFieldC[uint](Uint)
|
||||
case *uint:
|
||||
return Uintp(key, val)
|
||||
c = anyFieldC[*uint](Uintp)
|
||||
case []uint:
|
||||
return Uints(key, val)
|
||||
c = anyFieldC[[]uint](Uints)
|
||||
case uint64:
|
||||
return Uint64(key, val)
|
||||
c = anyFieldC[uint64](Uint64)
|
||||
case *uint64:
|
||||
return Uint64p(key, val)
|
||||
c = anyFieldC[*uint64](Uint64p)
|
||||
case []uint64:
|
||||
return Uint64s(key, val)
|
||||
c = anyFieldC[[]uint64](Uint64s)
|
||||
case uint32:
|
||||
return Uint32(key, val)
|
||||
c = anyFieldC[uint32](Uint32)
|
||||
case *uint32:
|
||||
return Uint32p(key, val)
|
||||
c = anyFieldC[*uint32](Uint32p)
|
||||
case []uint32:
|
||||
return Uint32s(key, val)
|
||||
c = anyFieldC[[]uint32](Uint32s)
|
||||
case uint16:
|
||||
return Uint16(key, val)
|
||||
c = anyFieldC[uint16](Uint16)
|
||||
case *uint16:
|
||||
return Uint16p(key, val)
|
||||
c = anyFieldC[*uint16](Uint16p)
|
||||
case []uint16:
|
||||
return Uint16s(key, val)
|
||||
c = anyFieldC[[]uint16](Uint16s)
|
||||
case uint8:
|
||||
return Uint8(key, val)
|
||||
c = anyFieldC[uint8](Uint8)
|
||||
case *uint8:
|
||||
return Uint8p(key, val)
|
||||
c = anyFieldC[*uint8](Uint8p)
|
||||
case []byte:
|
||||
return Binary(key, val)
|
||||
c = anyFieldC[[]byte](Binary)
|
||||
case uintptr:
|
||||
return Uintptr(key, val)
|
||||
c = anyFieldC[uintptr](Uintptr)
|
||||
case *uintptr:
|
||||
return Uintptrp(key, val)
|
||||
c = anyFieldC[*uintptr](Uintptrp)
|
||||
case []uintptr:
|
||||
return Uintptrs(key, val)
|
||||
c = anyFieldC[[]uintptr](Uintptrs)
|
||||
case time.Time:
|
||||
return Time(key, val)
|
||||
c = anyFieldC[time.Time](Time)
|
||||
case *time.Time:
|
||||
return Timep(key, val)
|
||||
c = anyFieldC[*time.Time](Timep)
|
||||
case []time.Time:
|
||||
return Times(key, val)
|
||||
c = anyFieldC[[]time.Time](Times)
|
||||
case time.Duration:
|
||||
return Duration(key, val)
|
||||
c = anyFieldC[time.Duration](Duration)
|
||||
case *time.Duration:
|
||||
return Durationp(key, val)
|
||||
c = anyFieldC[*time.Duration](Durationp)
|
||||
case []time.Duration:
|
||||
return Durations(key, val)
|
||||
c = anyFieldC[[]time.Duration](Durations)
|
||||
case error:
|
||||
return NamedError(key, val)
|
||||
c = anyFieldC[error](NamedError)
|
||||
case []error:
|
||||
return Errors(key, val)
|
||||
c = anyFieldC[[]error](Errors)
|
||||
case fmt.Stringer:
|
||||
return Stringer(key, val)
|
||||
c = anyFieldC[fmt.Stringer](Stringer)
|
||||
default:
|
||||
return Reflect(key, val)
|
||||
c = anyFieldC[any](Reflect)
|
||||
}
|
||||
|
||||
return c.Any(key, value)
|
||||
}
|
||||
|
2
vendor/go.uber.org/zap/internal/level_enabler.go
generated
vendored
2
vendor/go.uber.org/zap/internal/level_enabler.go
generated
vendored
@ -18,6 +18,8 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// Package internal and its subpackages hold types and functionality
|
||||
// that are not part of Zap's public API.
|
||||
package internal
|
||||
|
||||
import "go.uber.org/zap/zapcore"
|
||||
|
58
vendor/go.uber.org/zap/internal/pool/pool.go
generated
vendored
Normal file
58
vendor/go.uber.org/zap/internal/pool/pool.go
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2023 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 pool provides internal pool utilities.
|
||||
package pool
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A Pool is a generic wrapper around [sync.Pool] to provide strongly-typed
|
||||
// object pooling.
|
||||
//
|
||||
// Note that SA6002 (ref: https://staticcheck.io/docs/checks/#SA6002) will
|
||||
// not be detected, so all internal pool use must take care to only store
|
||||
// pointer types.
|
||||
type Pool[T any] struct {
|
||||
pool sync.Pool
|
||||
}
|
||||
|
||||
// New returns a new [Pool] for T, and will use fn to construct new Ts when
|
||||
// the pool is empty.
|
||||
func New[T any](fn func() T) *Pool[T] {
|
||||
return &Pool[T]{
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
return fn()
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Get gets a T from the pool, or creates a new one if the pool is empty.
|
||||
func (p *Pool[T]) Get() T {
|
||||
return p.pool.Get().(T)
|
||||
}
|
||||
|
||||
// Put returns x into the pool.
|
||||
func (p *Pool[T]) Put(x T) {
|
||||
p.pool.Put(x)
|
||||
}
|
9
vendor/go.uber.org/zap/level.go
generated
vendored
9
vendor/go.uber.org/zap/level.go
generated
vendored
@ -21,7 +21,8 @@
|
||||
package zap
|
||||
|
||||
import (
|
||||
"go.uber.org/atomic"
|
||||
"sync/atomic"
|
||||
|
||||
"go.uber.org/zap/internal"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
@ -76,9 +77,9 @@ var _ internal.LeveledEnabler = AtomicLevel{}
|
||||
// NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging
|
||||
// enabled.
|
||||
func NewAtomicLevel() AtomicLevel {
|
||||
return AtomicLevel{
|
||||
l: atomic.NewInt32(int32(InfoLevel)),
|
||||
}
|
||||
lvl := AtomicLevel{l: new(atomic.Int32)}
|
||||
lvl.l.Store(int32(InfoLevel))
|
||||
return lvl
|
||||
}
|
||||
|
||||
// NewAtomicLevelAt is a convenience function that creates an AtomicLevel
|
||||
|
13
vendor/go.uber.org/zap/logger.go
generated
vendored
13
vendor/go.uber.org/zap/logger.go
generated
vendored
@ -183,6 +183,13 @@ func (log *Logger) With(fields ...Field) *Logger {
|
||||
return l
|
||||
}
|
||||
|
||||
// Level reports the minimum enabled level for this logger.
|
||||
//
|
||||
// For NopLoggers, this is [zapcore.InvalidLevel].
|
||||
func (log *Logger) Level() zapcore.Level {
|
||||
return zapcore.LevelOf(log.core)
|
||||
}
|
||||
|
||||
// Check returns a CheckedEntry if logging a message at the specified level
|
||||
// is enabled. It's a completely optional optimization; in high-performance
|
||||
// applications, Check can help avoid allocating a slice to hold fields.
|
||||
@ -274,6 +281,12 @@ func (log *Logger) Core() zapcore.Core {
|
||||
return log.core
|
||||
}
|
||||
|
||||
// Name returns the Logger's underlying name,
|
||||
// or an empty string if the logger is unnamed.
|
||||
func (log *Logger) Name() string {
|
||||
return log.name
|
||||
}
|
||||
|
||||
func (log *Logger) clone() *Logger {
|
||||
copy := *log
|
||||
return ©
|
||||
|
3
vendor/go.uber.org/zap/options.go
generated
vendored
3
vendor/go.uber.org/zap/options.go
generated
vendored
@ -133,7 +133,8 @@ func IncreaseLevel(lvl zapcore.LevelEnabler) Option {
|
||||
}
|
||||
|
||||
// OnFatal sets the action to take on fatal logs.
|
||||
// Deprecated: Use WithFatalHook instead.
|
||||
//
|
||||
// Deprecated: Use [WithFatalHook] instead.
|
||||
func OnFatal(action zapcore.CheckWriteAction) Option {
|
||||
return WithFatalHook(action)
|
||||
}
|
||||
|
100
vendor/go.uber.org/zap/sink.go
generated
vendored
100
vendor/go.uber.org/zap/sink.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
// Copyright (c) 2016-2022 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
|
||||
@ -26,6 +26,7 @@ import (
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@ -34,23 +35,7 @@ import (
|
||||
|
||||
const schemeFile = "file"
|
||||
|
||||
var (
|
||||
_sinkMutex sync.RWMutex
|
||||
_sinkFactories map[string]func(*url.URL) (Sink, error) // keyed by scheme
|
||||
)
|
||||
|
||||
func init() {
|
||||
resetSinkRegistry()
|
||||
}
|
||||
|
||||
func resetSinkRegistry() {
|
||||
_sinkMutex.Lock()
|
||||
defer _sinkMutex.Unlock()
|
||||
|
||||
_sinkFactories = map[string]func(*url.URL) (Sink, error){
|
||||
schemeFile: newFileSink,
|
||||
}
|
||||
}
|
||||
var _sinkRegistry = newSinkRegistry()
|
||||
|
||||
// Sink defines the interface to write to and close logger destinations.
|
||||
type Sink interface {
|
||||
@ -58,10 +43,6 @@ type Sink interface {
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type nopCloserSink struct{ zapcore.WriteSyncer }
|
||||
|
||||
func (nopCloserSink) Close() error { return nil }
|
||||
|
||||
type errSinkNotFound struct {
|
||||
scheme string
|
||||
}
|
||||
@ -70,16 +51,29 @@ func (e *errSinkNotFound) Error() string {
|
||||
return fmt.Sprintf("no sink found for scheme %q", e.scheme)
|
||||
}
|
||||
|
||||
// RegisterSink registers a user-supplied factory for all sinks with a
|
||||
// particular scheme.
|
||||
//
|
||||
// All schemes must be ASCII, valid under section 3.1 of RFC 3986
|
||||
// (https://tools.ietf.org/html/rfc3986#section-3.1), and must not already
|
||||
// have a factory registered. Zap automatically registers a factory for the
|
||||
// "file" scheme.
|
||||
func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
_sinkMutex.Lock()
|
||||
defer _sinkMutex.Unlock()
|
||||
type nopCloserSink struct{ zapcore.WriteSyncer }
|
||||
|
||||
func (nopCloserSink) Close() error { return nil }
|
||||
|
||||
type sinkRegistry struct {
|
||||
mu sync.Mutex
|
||||
factories map[string]func(*url.URL) (Sink, error) // keyed by scheme
|
||||
openFile func(string, int, os.FileMode) (*os.File, error) // type matches os.OpenFile
|
||||
}
|
||||
|
||||
func newSinkRegistry() *sinkRegistry {
|
||||
sr := &sinkRegistry{
|
||||
factories: make(map[string]func(*url.URL) (Sink, error)),
|
||||
openFile: os.OpenFile,
|
||||
}
|
||||
sr.RegisterSink(schemeFile, sr.newFileSinkFromURL)
|
||||
return sr
|
||||
}
|
||||
|
||||
// RegisterScheme registers the given factory for the specific scheme.
|
||||
func (sr *sinkRegistry) RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
sr.mu.Lock()
|
||||
defer sr.mu.Unlock()
|
||||
|
||||
if scheme == "" {
|
||||
return errors.New("can't register a sink factory for empty string")
|
||||
@ -88,14 +82,22 @@ func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q is not a valid scheme: %v", scheme, err)
|
||||
}
|
||||
if _, ok := _sinkFactories[normalized]; ok {
|
||||
if _, ok := sr.factories[normalized]; ok {
|
||||
return fmt.Errorf("sink factory already registered for scheme %q", normalized)
|
||||
}
|
||||
_sinkFactories[normalized] = factory
|
||||
sr.factories[normalized] = factory
|
||||
return nil
|
||||
}
|
||||
|
||||
func newSink(rawURL string) (Sink, error) {
|
||||
func (sr *sinkRegistry) newSink(rawURL string) (Sink, error) {
|
||||
// URL parsing doesn't work well for Windows paths such as `c:\log.txt`, as scheme is set to
|
||||
// the drive, and path is unset unless `c:/log.txt` is used.
|
||||
// To avoid Windows-specific URL handling, we instead check IsAbs to open as a file.
|
||||
// filepath.IsAbs is OS-specific, so IsAbs('c:/log.txt') is false outside of Windows.
|
||||
if filepath.IsAbs(rawURL) {
|
||||
return sr.newFileSinkFromPath(rawURL)
|
||||
}
|
||||
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't parse %q as a URL: %v", rawURL, err)
|
||||
@ -104,16 +106,27 @@ func newSink(rawURL string) (Sink, error) {
|
||||
u.Scheme = schemeFile
|
||||
}
|
||||
|
||||
_sinkMutex.RLock()
|
||||
factory, ok := _sinkFactories[u.Scheme]
|
||||
_sinkMutex.RUnlock()
|
||||
sr.mu.Lock()
|
||||
factory, ok := sr.factories[u.Scheme]
|
||||
sr.mu.Unlock()
|
||||
if !ok {
|
||||
return nil, &errSinkNotFound{u.Scheme}
|
||||
}
|
||||
return factory(u)
|
||||
}
|
||||
|
||||
func newFileSink(u *url.URL) (Sink, error) {
|
||||
// RegisterSink registers a user-supplied factory for all sinks with a
|
||||
// particular scheme.
|
||||
//
|
||||
// All schemes must be ASCII, valid under section 0.1 of RFC 3986
|
||||
// (https://tools.ietf.org/html/rfc3983#section-3.1), and must not already
|
||||
// have a factory registered. Zap automatically registers a factory for the
|
||||
// "file" scheme.
|
||||
func RegisterSink(scheme string, factory func(*url.URL) (Sink, error)) error {
|
||||
return _sinkRegistry.RegisterSink(scheme, factory)
|
||||
}
|
||||
|
||||
func (sr *sinkRegistry) newFileSinkFromURL(u *url.URL) (Sink, error) {
|
||||
if u.User != nil {
|
||||
return nil, fmt.Errorf("user and password not allowed with file URLs: got %v", u)
|
||||
}
|
||||
@ -130,13 +143,18 @@ func newFileSink(u *url.URL) (Sink, error) {
|
||||
if hn := u.Hostname(); hn != "" && hn != "localhost" {
|
||||
return nil, fmt.Errorf("file URLs must leave host empty or use localhost: got %v", u)
|
||||
}
|
||||
switch u.Path {
|
||||
|
||||
return sr.newFileSinkFromPath(u.Path)
|
||||
}
|
||||
|
||||
func (sr *sinkRegistry) newFileSinkFromPath(path string) (Sink, error) {
|
||||
switch path {
|
||||
case "stdout":
|
||||
return nopCloserSink{os.Stdout}, nil
|
||||
case "stderr":
|
||||
return nopCloserSink{os.Stderr}, nil
|
||||
}
|
||||
return os.OpenFile(u.Path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
return sr.openFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
}
|
||||
|
||||
func normalizeScheme(s string) (string, error) {
|
||||
|
18
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
18
vendor/go.uber.org/zap/stacktrace.go
generated
vendored
@ -22,19 +22,17 @@ package zap
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap/buffer"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
var _stacktracePool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &stacktrace{
|
||||
storage: make([]uintptr, 64),
|
||||
}
|
||||
},
|
||||
}
|
||||
var _stacktracePool = pool.New(func() *stacktrace {
|
||||
return &stacktrace{
|
||||
storage: make([]uintptr, 64),
|
||||
}
|
||||
})
|
||||
|
||||
type stacktrace struct {
|
||||
pcs []uintptr // program counters; always a subslice of storage
|
||||
@ -68,7 +66,7 @@ const (
|
||||
//
|
||||
// The caller must call Free on the returned stacktrace after using it.
|
||||
func captureStacktrace(skip int, depth stacktraceDepth) *stacktrace {
|
||||
stack := _stacktracePool.Get().(*stacktrace)
|
||||
stack := _stacktracePool.Get()
|
||||
|
||||
switch depth {
|
||||
case stacktraceFirst:
|
||||
@ -154,7 +152,7 @@ func newStackFormatter(b *buffer.Buffer) stackFormatter {
|
||||
// the final runtime.main/runtime.goexit frame.
|
||||
func (sf *stackFormatter) FormatStack(stack *stacktrace) {
|
||||
// Note: On the last iteration, frames.Next() returns false, with a valid
|
||||
// frame, but we ignore this frame. The last frame is a a runtime frame which
|
||||
// frame, but we ignore this frame. The last frame is a runtime frame which
|
||||
// adds noise, since it's only either runtime.main or runtime.goexit.
|
||||
for frame, more := stack.Next(); more; frame, more = stack.Next() {
|
||||
sf.FormatFrame(frame)
|
||||
|
100
vendor/go.uber.org/zap/sugar.go
generated
vendored
100
vendor/go.uber.org/zap/sugar.go
generated
vendored
@ -31,6 +31,7 @@ import (
|
||||
const (
|
||||
_oddNumberErrMsg = "Ignored key without a value."
|
||||
_nonStringKeyErrMsg = "Ignored key-value pairs with non-string keys."
|
||||
_multipleErrMsg = "Multiple errors without a key."
|
||||
)
|
||||
|
||||
// A SugaredLogger wraps the base Logger functionality in a slower, but less
|
||||
@ -114,74 +115,95 @@ func (s *SugaredLogger) With(args ...interface{}) *SugaredLogger {
|
||||
return &SugaredLogger{base: s.base.With(s.sweetenFields(args)...)}
|
||||
}
|
||||
|
||||
// Debug uses fmt.Sprint to construct and log a message.
|
||||
// Level reports the minimum enabled level for this logger.
|
||||
//
|
||||
// For NopLoggers, this is [zapcore.InvalidLevel].
|
||||
func (s *SugaredLogger) Level() zapcore.Level {
|
||||
return zapcore.LevelOf(s.base.core)
|
||||
}
|
||||
|
||||
// Debug logs the provided arguments at [DebugLevel].
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Debug(args ...interface{}) {
|
||||
s.log(DebugLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Info uses fmt.Sprint to construct and log a message.
|
||||
// Info logs the provided arguments at [InfoLevel].
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Info(args ...interface{}) {
|
||||
s.log(InfoLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Warn uses fmt.Sprint to construct and log a message.
|
||||
// Warn logs the provided arguments at [WarnLevel].
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Warn(args ...interface{}) {
|
||||
s.log(WarnLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Error uses fmt.Sprint to construct and log a message.
|
||||
// Error logs the provided arguments at [ErrorLevel].
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Error(args ...interface{}) {
|
||||
s.log(ErrorLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// DPanic uses fmt.Sprint to construct and log a message. In development, the
|
||||
// logger then panics. (See DPanicLevel for details.)
|
||||
// DPanic logs the provided arguments at [DPanicLevel].
|
||||
// In development, the logger then panics. (See [DPanicLevel] for details.)
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) DPanic(args ...interface{}) {
|
||||
s.log(DPanicLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Panic uses fmt.Sprint to construct and log a message, then panics.
|
||||
// Panic constructs a message with the provided arguments and panics.
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Panic(args ...interface{}) {
|
||||
s.log(PanicLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
|
||||
// Fatal constructs a message with the provided arguments and calls os.Exit.
|
||||
// Spaces are added between arguments when neither is a string.
|
||||
func (s *SugaredLogger) Fatal(args ...interface{}) {
|
||||
s.log(FatalLevel, "", args, nil)
|
||||
}
|
||||
|
||||
// Debugf uses fmt.Sprintf to log a templated message.
|
||||
// Debugf formats the message according to the format specifier
|
||||
// and logs it at [DebugLevel].
|
||||
func (s *SugaredLogger) Debugf(template string, args ...interface{}) {
|
||||
s.log(DebugLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// Infof uses fmt.Sprintf to log a templated message.
|
||||
// Infof formats the message according to the format specifier
|
||||
// and logs it at [InfoLevel].
|
||||
func (s *SugaredLogger) Infof(template string, args ...interface{}) {
|
||||
s.log(InfoLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// Warnf uses fmt.Sprintf to log a templated message.
|
||||
// Warnf formats the message according to the format specifier
|
||||
// and logs it at [WarnLevel].
|
||||
func (s *SugaredLogger) Warnf(template string, args ...interface{}) {
|
||||
s.log(WarnLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// Errorf uses fmt.Sprintf to log a templated message.
|
||||
// Errorf formats the message according to the format specifier
|
||||
// and logs it at [ErrorLevel].
|
||||
func (s *SugaredLogger) Errorf(template string, args ...interface{}) {
|
||||
s.log(ErrorLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// DPanicf uses fmt.Sprintf to log a templated message. In development, the
|
||||
// logger then panics. (See DPanicLevel for details.)
|
||||
// DPanicf formats the message according to the format specifier
|
||||
// and logs it at [DPanicLevel].
|
||||
// In development, the logger then panics. (See [DPanicLevel] for details.)
|
||||
func (s *SugaredLogger) DPanicf(template string, args ...interface{}) {
|
||||
s.log(DPanicLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// Panicf uses fmt.Sprintf to log a templated message, then panics.
|
||||
// Panicf formats the message according to the format specifier
|
||||
// and panics.
|
||||
func (s *SugaredLogger) Panicf(template string, args ...interface{}) {
|
||||
s.log(PanicLevel, template, args, nil)
|
||||
}
|
||||
|
||||
// Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
|
||||
// Fatalf formats the message according to the format specifier
|
||||
// and calls os.Exit.
|
||||
func (s *SugaredLogger) Fatalf(template string, args ...interface{}) {
|
||||
s.log(FatalLevel, template, args, nil)
|
||||
}
|
||||
@ -233,38 +255,45 @@ func (s *SugaredLogger) Fatalw(msg string, keysAndValues ...interface{}) {
|
||||
s.log(FatalLevel, msg, nil, keysAndValues)
|
||||
}
|
||||
|
||||
// Debugln uses fmt.Sprintln to construct and log a message.
|
||||
// Debugln logs a message at [DebugLevel].
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Debugln(args ...interface{}) {
|
||||
s.logln(DebugLevel, args, nil)
|
||||
}
|
||||
|
||||
// Infoln uses fmt.Sprintln to construct and log a message.
|
||||
// Infoln logs a message at [InfoLevel].
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Infoln(args ...interface{}) {
|
||||
s.logln(InfoLevel, args, nil)
|
||||
}
|
||||
|
||||
// Warnln uses fmt.Sprintln to construct and log a message.
|
||||
// Warnln logs a message at [WarnLevel].
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Warnln(args ...interface{}) {
|
||||
s.logln(WarnLevel, args, nil)
|
||||
}
|
||||
|
||||
// Errorln uses fmt.Sprintln to construct and log a message.
|
||||
// Errorln logs a message at [ErrorLevel].
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Errorln(args ...interface{}) {
|
||||
s.logln(ErrorLevel, args, nil)
|
||||
}
|
||||
|
||||
// DPanicln uses fmt.Sprintln to construct and log a message. In development, the
|
||||
// logger then panics. (See DPanicLevel for details.)
|
||||
// DPanicln logs a message at [DPanicLevel].
|
||||
// In development, the logger then panics. (See [DPanicLevel] for details.)
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) DPanicln(args ...interface{}) {
|
||||
s.logln(DPanicLevel, args, nil)
|
||||
}
|
||||
|
||||
// Panicln uses fmt.Sprintln to construct and log a message, then panics.
|
||||
// Panicln logs a message at [PanicLevel] and panics.
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Panicln(args ...interface{}) {
|
||||
s.logln(PanicLevel, args, nil)
|
||||
}
|
||||
|
||||
// Fatalln uses fmt.Sprintln to construct and log a message, then calls os.Exit.
|
||||
// Fatalln logs a message at [FatalLevel] and calls os.Exit.
|
||||
// Spaces are always added between arguments.
|
||||
func (s *SugaredLogger) Fatalln(args ...interface{}) {
|
||||
s.logln(FatalLevel, args, nil)
|
||||
}
|
||||
@ -329,10 +358,13 @@ func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Allocate enough space for the worst case; if users pass only structured
|
||||
// fields, we shouldn't penalize them with extra allocations.
|
||||
fields := make([]Field, 0, len(args))
|
||||
var invalid invalidPairs
|
||||
var (
|
||||
// Allocate enough space for the worst case; if users pass only structured
|
||||
// fields, we shouldn't penalize them with extra allocations.
|
||||
fields = make([]Field, 0, len(args))
|
||||
invalid invalidPairs
|
||||
seenError bool
|
||||
)
|
||||
|
||||
for i := 0; i < len(args); {
|
||||
// This is a strongly-typed field. Consume it and move on.
|
||||
@ -342,6 +374,18 @@ func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
continue
|
||||
}
|
||||
|
||||
// If it is an error, consume it and move on.
|
||||
if err, ok := args[i].(error); ok {
|
||||
if !seenError {
|
||||
seenError = true
|
||||
fields = append(fields, Error(err))
|
||||
} else {
|
||||
s.base.Error(_multipleErrMsg, Error(err))
|
||||
}
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
// Make sure this element isn't a dangling key.
|
||||
if i == len(args)-1 {
|
||||
s.base.Error(_oddNumberErrMsg, Any("ignored", args[i]))
|
||||
|
2
vendor/go.uber.org/zap/writer.go
generated
vendored
2
vendor/go.uber.org/zap/writer.go
generated
vendored
@ -68,7 +68,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
|
||||
var openErr error
|
||||
for _, path := range paths {
|
||||
sink, err := newSink(path)
|
||||
sink, err := _sinkRegistry.newSink(path)
|
||||
if err != nil {
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("open sink %q: %w", path, err))
|
||||
continue
|
||||
|
14
vendor/go.uber.org/zap/zapcore/console_encoder.go
generated
vendored
14
vendor/go.uber.org/zap/zapcore/console_encoder.go
generated
vendored
@ -22,20 +22,20 @@ package zapcore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap/buffer"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
var _sliceEncoderPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &sliceArrayEncoder{elems: make([]interface{}, 0, 2)}
|
||||
},
|
||||
}
|
||||
var _sliceEncoderPool = pool.New(func() *sliceArrayEncoder {
|
||||
return &sliceArrayEncoder{
|
||||
elems: make([]interface{}, 0, 2),
|
||||
}
|
||||
})
|
||||
|
||||
func getSliceEncoder() *sliceArrayEncoder {
|
||||
return _sliceEncoderPool.Get().(*sliceArrayEncoder)
|
||||
return _sliceEncoderPool.Get()
|
||||
}
|
||||
|
||||
func putSliceEncoder(e *sliceArrayEncoder) {
|
||||
|
21
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
21
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
@ -24,25 +24,23 @@ import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/exit"
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
var (
|
||||
_cePool = sync.Pool{New: func() interface{} {
|
||||
// Pre-allocate some space for cores.
|
||||
return &CheckedEntry{
|
||||
cores: make([]Core, 4),
|
||||
}
|
||||
}}
|
||||
)
|
||||
var _cePool = pool.New(func() *CheckedEntry {
|
||||
// Pre-allocate some space for cores.
|
||||
return &CheckedEntry{
|
||||
cores: make([]Core, 4),
|
||||
}
|
||||
})
|
||||
|
||||
func getCheckedEntry() *CheckedEntry {
|
||||
ce := _cePool.Get().(*CheckedEntry)
|
||||
ce := _cePool.Get()
|
||||
ce.reset()
|
||||
return ce
|
||||
}
|
||||
@ -281,7 +279,8 @@ func (ce *CheckedEntry) AddCore(ent Entry, core Core) *CheckedEntry {
|
||||
// Should sets this CheckedEntry's CheckWriteAction, which controls whether a
|
||||
// Core will panic or fatal after writing this log entry. Like AddCore, it's
|
||||
// safe to call on nil CheckedEntry references.
|
||||
// Deprecated: Use After(ent Entry, after CheckWriteHook) instead.
|
||||
//
|
||||
// Deprecated: Use [CheckedEntry.After] instead.
|
||||
func (ce *CheckedEntry) Should(ent Entry, should CheckWriteAction) *CheckedEntry {
|
||||
return ce.After(ent, should)
|
||||
}
|
||||
|
9
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
@ -23,7 +23,8 @@ package zapcore
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
// Encodes the given error into fields of an object. A field with the given
|
||||
@ -103,9 +104,9 @@ func (errs errArray) MarshalLogArray(arr ArrayEncoder) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _errArrayElemPool = sync.Pool{New: func() interface{} {
|
||||
var _errArrayElemPool = pool.New(func() *errArrayElem {
|
||||
return &errArrayElem{}
|
||||
}}
|
||||
})
|
||||
|
||||
// Encodes any error into a {"error": ...} re-using the same errors logic.
|
||||
//
|
||||
@ -113,7 +114,7 @@ var _errArrayElemPool = sync.Pool{New: func() interface{} {
|
||||
type errArrayElem struct{ err error }
|
||||
|
||||
func newErrArrayElem(err error) *errArrayElem {
|
||||
e := _errArrayElemPool.Get().(*errArrayElem)
|
||||
e := _errArrayElemPool.Get()
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
14
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
14
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
@ -23,24 +23,20 @@ package zapcore
|
||||
import (
|
||||
"encoding/base64"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"go.uber.org/zap/buffer"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/pool"
|
||||
)
|
||||
|
||||
// For JSON-escaping; see jsonEncoder.safeAddString below.
|
||||
const _hex = "0123456789abcdef"
|
||||
|
||||
var _jsonPool = sync.Pool{New: func() interface{} {
|
||||
var _jsonPool = pool.New(func() *jsonEncoder {
|
||||
return &jsonEncoder{}
|
||||
}}
|
||||
|
||||
func getJSONEncoder() *jsonEncoder {
|
||||
return _jsonPool.Get().(*jsonEncoder)
|
||||
}
|
||||
})
|
||||
|
||||
func putJSONEncoder(enc *jsonEncoder) {
|
||||
if enc.reflectBuf != nil {
|
||||
@ -354,7 +350,7 @@ func (enc *jsonEncoder) Clone() Encoder {
|
||||
}
|
||||
|
||||
func (enc *jsonEncoder) clone() *jsonEncoder {
|
||||
clone := getJSONEncoder()
|
||||
clone := _jsonPool.Get()
|
||||
clone.EncoderConfig = enc.EncoderConfig
|
||||
clone.spaced = enc.spaced
|
||||
clone.openNamespaces = enc.openNamespaces
|
||||
@ -527,7 +523,7 @@ func (enc *jsonEncoder) tryAddRuneSelf(b byte) bool {
|
||||
if b >= utf8.RuneSelf {
|
||||
return false
|
||||
}
|
||||
if 0x20 <= b && b != '\\' && b != '"' {
|
||||
if b >= 0x20 && b != '\\' && b != '"' {
|
||||
enc.buf.AppendByte(b)
|
||||
return true
|
||||
}
|
||||
|
9
vendor/go.uber.org/zap/zapcore/sampler.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/sampler.go
generated
vendored
@ -21,9 +21,8 @@
|
||||
package zapcore
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -66,16 +65,16 @@ func (c *counter) IncCheckReset(t time.Time, tick time.Duration) uint64 {
|
||||
tn := t.UnixNano()
|
||||
resetAfter := c.resetAt.Load()
|
||||
if resetAfter > tn {
|
||||
return c.counter.Inc()
|
||||
return c.counter.Add(1)
|
||||
}
|
||||
|
||||
c.counter.Store(1)
|
||||
|
||||
newResetAfter := tn + tick.Nanoseconds()
|
||||
if !c.resetAt.CAS(resetAfter, newResetAfter) {
|
||||
if !c.resetAt.CompareAndSwap(resetAfter, newResetAfter) {
|
||||
// We raced with another goroutine trying to reset, and it also reset
|
||||
// the counter to 1, so we need to reincrement the counter.
|
||||
return c.counter.Inc()
|
||||
return c.counter.Add(1)
|
||||
}
|
||||
|
||||
return 1
|
||||
|
Reference in New Issue
Block a user