chore: upgrade dependencies
This commit is contained in:
40
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
40
vendor/go.uber.org/zap/CHANGELOG.md
generated
vendored
@ -3,6 +3,46 @@ 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.23.0 (24 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1147][]: Add a `zapcore.LevelOf` function to determine the level of a
|
||||
`LevelEnabler` or `Core`.
|
||||
* [#1155][]: Add `zap.Stringers` field constructor to log arrays of objects
|
||||
that implement `String() string`.
|
||||
|
||||
[#1147]: https://github.com/uber-go/zap/pull/1147
|
||||
[#1155]: https://github.com/uber-go/zap/pull/1155
|
||||
|
||||
|
||||
## 1.22.0 (8 Aug 2022)
|
||||
|
||||
Enhancements:
|
||||
* [#1071][]: Add `zap.Objects` and `zap.ObjectValues` field constructors to log
|
||||
arrays of objects. With these two constructors, you don't need to implement
|
||||
`zapcore.ArrayMarshaler` for use with `zap.Array` if those objects implement
|
||||
`zapcore.ObjectMarshaler`.
|
||||
* [#1079][]: Add `SugaredLogger.WithOptions` to build a copy of an existing
|
||||
`SugaredLogger` with the provided options applied.
|
||||
* [#1080][]: Add `*ln` variants to `SugaredLogger` for each log level.
|
||||
These functions provide a string joining behavior similar to `fmt.Println`.
|
||||
* [#1088][]: Add `zap.WithFatalHook` option to control the behavior of the
|
||||
logger for `Fatal`-level log entries. This defaults to exiting the program.
|
||||
* [#1108][]: Add a `zap.Must` function that you can use with `NewProduction` or
|
||||
`NewDevelopment` to panic if the system was unable to build the logger.
|
||||
* [#1118][]: Add a `Logger.Log` method that allows specifying the log level for
|
||||
a statement dynamically.
|
||||
|
||||
Thanks to @cardil, @craigpastro, @sashamelentyev, @shota3506, and @zhupeijun
|
||||
for their contributions to this release.
|
||||
|
||||
[#1071]: https://github.com/uber-go/zap/pull/1071
|
||||
[#1079]: https://github.com/uber-go/zap/pull/1079
|
||||
[#1080]: https://github.com/uber-go/zap/pull/1080
|
||||
[#1088]: https://github.com/uber-go/zap/pull/1088
|
||||
[#1108]: https://github.com/uber-go/zap/pull/1108
|
||||
[#1118]: https://github.com/uber-go/zap/pull/1118
|
||||
|
||||
## 1.21.0 (7 Feb 2022)
|
||||
|
||||
Enhancements:
|
||||
|
21
vendor/go.uber.org/zap/CONTRIBUTING.md
generated
vendored
21
vendor/go.uber.org/zap/CONTRIBUTING.md
generated
vendored
@ -16,7 +16,7 @@ you to accept the CLA when you open your pull request.
|
||||
|
||||
[Fork][fork], then clone the repository:
|
||||
|
||||
```
|
||||
```bash
|
||||
mkdir -p $GOPATH/src/go.uber.org
|
||||
cd $GOPATH/src/go.uber.org
|
||||
git clone git@github.com:your_github_username/zap.git
|
||||
@ -27,21 +27,16 @@ git fetch upstream
|
||||
|
||||
Make sure that the tests and the linters pass:
|
||||
|
||||
```
|
||||
```bash
|
||||
make test
|
||||
make lint
|
||||
```
|
||||
|
||||
If you're not using the minor version of Go specified in the Makefile's
|
||||
`LINTABLE_MINOR_VERSIONS` variable, `make lint` doesn't do anything. This is
|
||||
fine, but it means that you'll only discover lint failures after you open your
|
||||
pull request.
|
||||
|
||||
## Making Changes
|
||||
|
||||
Start by creating a new branch for your changes:
|
||||
|
||||
```
|
||||
```bash
|
||||
cd $GOPATH/src/go.uber.org/zap
|
||||
git checkout master
|
||||
git fetch upstream
|
||||
@ -52,22 +47,22 @@ git checkout -b cool_new_feature
|
||||
Make your changes, then ensure that `make lint` and `make test` still pass. If
|
||||
you're satisfied with your changes, push them to your fork.
|
||||
|
||||
```
|
||||
```bash
|
||||
git push origin cool_new_feature
|
||||
```
|
||||
|
||||
Then use the GitHub UI to open a pull request.
|
||||
|
||||
At this point, you're waiting on us to review your changes. We *try* to respond
|
||||
At this point, you're waiting on us to review your changes. We _try_ to respond
|
||||
to issues and pull requests within a few business days, and we may suggest some
|
||||
improvements or alternatives. Once your changes are approved, one of the
|
||||
project maintainers will merge them.
|
||||
|
||||
We're much more likely to approve your changes if you:
|
||||
|
||||
* Add tests for new functionality.
|
||||
* Write a [good commit message][commit-message].
|
||||
* Maintain backward compatibility.
|
||||
- Add tests for new functionality.
|
||||
- Write a [good commit message][commit-message].
|
||||
- Maintain backward compatibility.
|
||||
|
||||
[fork]: https://github.com/uber-go/zap/fork
|
||||
[open-issue]: https://github.com/uber-go/zap/issues/new
|
||||
|
59
vendor/go.uber.org/zap/README.md
generated
vendored
59
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,40 @@ 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 | 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 |
|
||||
|
||||
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 | 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 |
|
||||
|
||||
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 | 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 |
|
||||
|
||||
## Development Status: Stable
|
||||
|
||||
@ -131,4 +131,3 @@ 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
|
||||
|
||||
|
156
vendor/go.uber.org/zap/array_go118.go
generated
vendored
Normal file
156
vendor/go.uber.org/zap/array_go118.go
generated
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
// Copyright (c) 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
|
||||
// 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.
|
||||
|
||||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// Objects constructs a field with the given key, holding a list of the
|
||||
// provided objects that can be marshaled by Zap.
|
||||
//
|
||||
// Note that these objects must implement zapcore.ObjectMarshaler directly.
|
||||
// That is, if you're trying to marshal a []Request, the MarshalLogObject
|
||||
// method must be declared on the Request type, not its pointer (*Request).
|
||||
// If it's on the pointer, use ObjectValues.
|
||||
//
|
||||
// Given an object that implements MarshalLogObject on the value receiver, you
|
||||
// can log a slice of those objects with Objects like so:
|
||||
//
|
||||
// type Author struct{ ... }
|
||||
// func (a Author) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var authors []Author = ...
|
||||
// logger.Info("loading article", zap.Objects("authors", authors))
|
||||
//
|
||||
// Similarly, given a type that implements MarshalLogObject on its pointer
|
||||
// receiver, you can log a slice of pointers to that object with Objects like
|
||||
// so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
//
|
||||
// If instead, you have a slice of values of such an object, use the
|
||||
// ObjectValues constructor.
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
|
||||
func Objects[T zapcore.ObjectMarshaler](key string, values []T) Field {
|
||||
return Array(key, objects[T](values))
|
||||
}
|
||||
|
||||
type objects[T zapcore.ObjectMarshaler] []T
|
||||
|
||||
func (os objects[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for _, o := range os {
|
||||
if err := arr.AppendObject(o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// objectMarshalerPtr is a constraint that specifies that the given type
|
||||
// implements zapcore.ObjectMarshaler on a pointer receiver.
|
||||
type objectMarshalerPtr[T any] interface {
|
||||
*T
|
||||
zapcore.ObjectMarshaler
|
||||
}
|
||||
|
||||
// ObjectValues constructs a field with the given key, holding a list of the
|
||||
// provided objects, where pointers to these objects can be marshaled by Zap.
|
||||
//
|
||||
// Note that pointers to these objects must implement zapcore.ObjectMarshaler.
|
||||
// That is, if you're trying to marshal a []Request, the MarshalLogObject
|
||||
// method must be declared on the *Request type, not the value (Request).
|
||||
// If it's on the value, use Objects.
|
||||
//
|
||||
// Given an object that implements MarshalLogObject on the pointer receiver,
|
||||
// you can log a slice of those objects with ObjectValues like so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.ObjectValues("requests", requests))
|
||||
//
|
||||
// If instead, you have a slice of pointers of such an object, use the Objects
|
||||
// field constructor.
|
||||
//
|
||||
// var requests []*Request = ...
|
||||
// logger.Info("sending requests", zap.Objects("requests", requests))
|
||||
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
|
||||
|
||||
func (os objectValues[T, P]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for i := range os {
|
||||
// It is necessary for us to explicitly reference the "P" type.
|
||||
// We cannot simply pass "&os[i]" to AppendObject because its type
|
||||
// is "*T", which the type system does not consider as
|
||||
// implementing ObjectMarshaler.
|
||||
// Only the type "P" satisfies ObjectMarshaler, which we have
|
||||
// to convert "*T" to explicitly.
|
||||
var p P = &os[i]
|
||||
if err := arr.AppendObject(p); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stringers constructs a field with the given key, holding a list of the
|
||||
// output provided by the value's String method
|
||||
//
|
||||
// Given an object that implements String on the value receiver, you
|
||||
// can log a slice of those objects with Objects like so:
|
||||
//
|
||||
// type Request struct{ ... }
|
||||
// func (a Request) String() string
|
||||
//
|
||||
// var requests []Request = ...
|
||||
// logger.Info("sending requests", zap.Stringers("requests", requests))
|
||||
//
|
||||
// Note that these objects must implement fmt.Stringer directly.
|
||||
// That is, if you're trying to marshal a []Request, the String method
|
||||
// must be declared on the Request type, not its pointer (*Request).
|
||||
func Stringers[T fmt.Stringer](key string, values []T) Field {
|
||||
return Array(key, stringers[T](values))
|
||||
}
|
||||
|
||||
type stringers[T fmt.Stringer] []T
|
||||
|
||||
func (os stringers[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error {
|
||||
for _, o := range os {
|
||||
arr.AppendString(o.String())
|
||||
}
|
||||
return nil
|
||||
}
|
4
vendor/go.uber.org/zap/config.go
generated
vendored
4
vendor/go.uber.org/zap/config.go
generated
vendored
@ -21,7 +21,7 @@
|
||||
package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -182,7 +182,7 @@ func (cfg Config) Build(opts ...Option) (*Logger, error) {
|
||||
}
|
||||
|
||||
if cfg.Level == (AtomicLevel{}) {
|
||||
return nil, fmt.Errorf("missing Level")
|
||||
return nil, errors.New("missing Level")
|
||||
}
|
||||
|
||||
log := New(
|
||||
|
60
vendor/go.uber.org/zap/doc.go
generated
vendored
60
vendor/go.uber.org/zap/doc.go
generated
vendored
@ -32,7 +32,7 @@
|
||||
// they need to count every allocation and when they'd prefer a more familiar,
|
||||
// loosely typed API.
|
||||
//
|
||||
// Choosing a Logger
|
||||
// # Choosing a Logger
|
||||
//
|
||||
// In contexts where performance is nice, but not critical, use the
|
||||
// SugaredLogger. It's 4-10x faster than other structured logging packages and
|
||||
@ -41,14 +41,15 @@
|
||||
// variadic number of key-value pairs. (For more advanced use cases, they also
|
||||
// accept strongly typed fields - see the SugaredLogger.With documentation for
|
||||
// details.)
|
||||
// sugar := zap.NewExample().Sugar()
|
||||
// defer sugar.Sync()
|
||||
// sugar.Infow("failed to fetch URL",
|
||||
// "url", "http://example.com",
|
||||
// "attempt", 3,
|
||||
// "backoff", time.Second,
|
||||
// )
|
||||
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
|
||||
//
|
||||
// sugar := zap.NewExample().Sugar()
|
||||
// defer sugar.Sync()
|
||||
// sugar.Infow("failed to fetch URL",
|
||||
// "url", "http://example.com",
|
||||
// "attempt", 3,
|
||||
// "backoff", time.Second,
|
||||
// )
|
||||
// sugar.Infof("failed to fetch URL: %s", "http://example.com")
|
||||
//
|
||||
// By default, loggers are unbuffered. However, since zap's low-level APIs
|
||||
// allow buffering, calling Sync before letting your process exit is a good
|
||||
@ -57,32 +58,35 @@
|
||||
// In the rare contexts where every microsecond and every allocation matter,
|
||||
// use the Logger. It's even faster than the SugaredLogger and allocates far
|
||||
// less, but it only supports strongly-typed, structured logging.
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// logger.Info("failed to fetch URL",
|
||||
// zap.String("url", "http://example.com"),
|
||||
// zap.Int("attempt", 3),
|
||||
// zap.Duration("backoff", time.Second),
|
||||
// )
|
||||
//
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// logger.Info("failed to fetch URL",
|
||||
// zap.String("url", "http://example.com"),
|
||||
// zap.Int("attempt", 3),
|
||||
// zap.Duration("backoff", time.Second),
|
||||
// )
|
||||
//
|
||||
// Choosing between the Logger and SugaredLogger doesn't need to be an
|
||||
// application-wide decision: converting between the two is simple and
|
||||
// inexpensive.
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// sugar := logger.Sugar()
|
||||
// plain := sugar.Desugar()
|
||||
//
|
||||
// Configuring Zap
|
||||
// logger := zap.NewExample()
|
||||
// defer logger.Sync()
|
||||
// sugar := logger.Sugar()
|
||||
// plain := sugar.Desugar()
|
||||
//
|
||||
// # Configuring Zap
|
||||
//
|
||||
// The simplest way to build a Logger is to use zap's opinionated presets:
|
||||
// NewExample, NewProduction, and NewDevelopment. These presets build a logger
|
||||
// with a single function call:
|
||||
// logger, err := zap.NewProduction()
|
||||
// if err != nil {
|
||||
// log.Fatalf("can't initialize zap logger: %v", err)
|
||||
// }
|
||||
// defer logger.Sync()
|
||||
//
|
||||
// logger, err := zap.NewProduction()
|
||||
// if err != nil {
|
||||
// log.Fatalf("can't initialize zap logger: %v", err)
|
||||
// }
|
||||
// defer logger.Sync()
|
||||
//
|
||||
// Presets are fine for small projects, but larger projects and organizations
|
||||
// naturally require a bit more customization. For most users, zap's Config
|
||||
@ -94,7 +98,7 @@
|
||||
// go.uber.org/zap/zapcore. See the package-level AdvancedConfiguration
|
||||
// example for sample code.
|
||||
//
|
||||
// Extending Zap
|
||||
// # Extending Zap
|
||||
//
|
||||
// The zap package itself is a relatively thin wrapper around the interfaces
|
||||
// in go.uber.org/zap/zapcore. Extending zap to support a new encoding (e.g.,
|
||||
@ -106,7 +110,7 @@
|
||||
// Similarly, package authors can use the high-performance Encoder and Core
|
||||
// implementations in the zapcore package to build their own loggers.
|
||||
//
|
||||
// Frequently Asked Questions
|
||||
// # Frequently Asked Questions
|
||||
//
|
||||
// An FAQ covering everything from installation errors to design decisions is
|
||||
// available at https://github.com/uber-go/zap/blob/master/FAQ.md.
|
||||
|
2
vendor/go.uber.org/zap/encoder.go
generated
vendored
2
vendor/go.uber.org/zap/encoder.go
generated
vendored
@ -63,7 +63,7 @@ func RegisterEncoder(name string, constructor func(zapcore.EncoderConfig) (zapco
|
||||
|
||||
func newEncoder(name string, encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {
|
||||
if encoderConfig.TimeKey != "" && encoderConfig.EncodeTime == nil {
|
||||
return nil, fmt.Errorf("missing EncodeTime in EncoderConfig")
|
||||
return nil, errors.New("missing EncodeTime in EncoderConfig")
|
||||
}
|
||||
|
||||
_encoderMutex.RLock()
|
||||
|
25
vendor/go.uber.org/zap/http_handler.go
generated
vendored
25
vendor/go.uber.org/zap/http_handler.go
generated
vendored
@ -22,6 +22,7 @@ package zap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -32,22 +33,23 @@ import (
|
||||
// ServeHTTP is a simple JSON endpoint that can report on or change the current
|
||||
// logging level.
|
||||
//
|
||||
// GET
|
||||
// # GET
|
||||
//
|
||||
// The GET request returns a JSON description of the current logging level like:
|
||||
// {"level":"info"}
|
||||
//
|
||||
// PUT
|
||||
// {"level":"info"}
|
||||
//
|
||||
// # PUT
|
||||
//
|
||||
// The PUT request changes the logging level. It is perfectly safe to change the
|
||||
// logging level while a program is running. Two content types are supported:
|
||||
//
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
// Content-Type: application/x-www-form-urlencoded
|
||||
//
|
||||
// With this content type, the level can be provided through the request body or
|
||||
// a query parameter. The log level is URL encoded like:
|
||||
//
|
||||
// level=debug
|
||||
// level=debug
|
||||
//
|
||||
// The request body takes precedence over the query parameter, if both are
|
||||
// specified.
|
||||
@ -55,18 +57,17 @@ import (
|
||||
// This content type is the default for a curl PUT request. Following are two
|
||||
// example curl requests that both set the logging level to debug.
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level?level=debug
|
||||
// curl -X PUT localhost:8080/log/level -d level=debug
|
||||
// curl -X PUT localhost:8080/log/level?level=debug
|
||||
// curl -X PUT localhost:8080/log/level -d level=debug
|
||||
//
|
||||
// For any other content type, the payload is expected to be JSON encoded and
|
||||
// look like:
|
||||
//
|
||||
// {"level":"info"}
|
||||
// {"level":"info"}
|
||||
//
|
||||
// An example curl request could look like this:
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
|
||||
//
|
||||
// curl -X PUT localhost:8080/log/level -H "Content-Type: application/json" -d '{"level":"debug"}'
|
||||
func (lvl AtomicLevel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
type errorResponse struct {
|
||||
Error string `json:"error"`
|
||||
@ -108,7 +109,7 @@ func decodePutRequest(contentType string, r *http.Request) (zapcore.Level, error
|
||||
func decodePutURL(r *http.Request) (zapcore.Level, error) {
|
||||
lvl := r.FormValue("level")
|
||||
if lvl == "" {
|
||||
return 0, fmt.Errorf("must specify logging level")
|
||||
return 0, errors.New("must specify logging level")
|
||||
}
|
||||
var l zapcore.Level
|
||||
if err := l.UnmarshalText([]byte(lvl)); err != nil {
|
||||
@ -125,7 +126,7 @@ func decodePutJSON(body io.Reader) (zapcore.Level, error) {
|
||||
return 0, fmt.Errorf("malformed request body: %v", err)
|
||||
}
|
||||
if pld.Level == nil {
|
||||
return 0, fmt.Errorf("must specify logging level")
|
||||
return 0, errors.New("must specify logging level")
|
||||
}
|
||||
return *pld.Level, nil
|
||||
|
||||
|
22
vendor/go.uber.org/zap/internal/exit/exit.go
generated
vendored
22
vendor/go.uber.org/zap/internal/exit/exit.go
generated
vendored
@ -24,24 +24,25 @@ package exit
|
||||
|
||||
import "os"
|
||||
|
||||
var real = func() { os.Exit(1) }
|
||||
var _exit = os.Exit
|
||||
|
||||
// Exit normally terminates the process by calling os.Exit(1). If the package
|
||||
// is stubbed, it instead records a call in the testing spy.
|
||||
func Exit() {
|
||||
real()
|
||||
// With terminates the process by calling os.Exit(code). If the package is
|
||||
// stubbed, it instead records a call in the testing spy.
|
||||
func With(code int) {
|
||||
_exit(code)
|
||||
}
|
||||
|
||||
// A StubbedExit is a testing fake for os.Exit.
|
||||
type StubbedExit struct {
|
||||
Exited bool
|
||||
prev func()
|
||||
Code int
|
||||
prev func(code int)
|
||||
}
|
||||
|
||||
// Stub substitutes a fake for the call to os.Exit(1).
|
||||
func Stub() *StubbedExit {
|
||||
s := &StubbedExit{prev: real}
|
||||
real = s.exit
|
||||
s := &StubbedExit{prev: _exit}
|
||||
_exit = s.exit
|
||||
return s
|
||||
}
|
||||
|
||||
@ -56,9 +57,10 @@ func WithStub(f func()) *StubbedExit {
|
||||
|
||||
// Unstub restores the previous exit function.
|
||||
func (se *StubbedExit) Unstub() {
|
||||
real = se.prev
|
||||
_exit = se.prev
|
||||
}
|
||||
|
||||
func (se *StubbedExit) exit() {
|
||||
func (se *StubbedExit) exit(code int) {
|
||||
se.Exited = true
|
||||
se.Code = code
|
||||
}
|
||||
|
35
vendor/go.uber.org/zap/internal/level_enabler.go
generated
vendored
Normal file
35
vendor/go.uber.org/zap/internal/level_enabler.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (c) 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
|
||||
// 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 internal
|
||||
|
||||
import "go.uber.org/zap/zapcore"
|
||||
|
||||
// LeveledEnabler is an interface satisfied by LevelEnablers that are able to
|
||||
// report their own level.
|
||||
//
|
||||
// This interface is defined to use more conveniently in tests and non-zapcore
|
||||
// packages.
|
||||
// This cannot be imported from zapcore because of the cyclic dependency.
|
||||
type LeveledEnabler interface {
|
||||
zapcore.LevelEnabler
|
||||
|
||||
Level() zapcore.Level
|
||||
}
|
3
vendor/go.uber.org/zap/level.go
generated
vendored
3
vendor/go.uber.org/zap/level.go
generated
vendored
@ -22,6 +22,7 @@ package zap
|
||||
|
||||
import (
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap/internal"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
@ -70,6 +71,8 @@ type AtomicLevel struct {
|
||||
l *atomic.Int32
|
||||
}
|
||||
|
||||
var _ internal.LeveledEnabler = AtomicLevel{}
|
||||
|
||||
// NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging
|
||||
// enabled.
|
||||
func NewAtomicLevel() AtomicLevel {
|
||||
|
48
vendor/go.uber.org/zap/logger.go
generated
vendored
48
vendor/go.uber.org/zap/logger.go
generated
vendored
@ -22,7 +22,7 @@ package zap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -42,7 +42,7 @@ type Logger struct {
|
||||
|
||||
development bool
|
||||
addCaller bool
|
||||
onFatal zapcore.CheckWriteAction // default is WriteThenFatal
|
||||
onFatal zapcore.CheckWriteHook // default is WriteThenFatal
|
||||
|
||||
name string
|
||||
errorOutput zapcore.WriteSyncer
|
||||
@ -85,7 +85,7 @@ func New(core zapcore.Core, options ...Option) *Logger {
|
||||
func NewNop() *Logger {
|
||||
return &Logger{
|
||||
core: zapcore.NewNopCore(),
|
||||
errorOutput: zapcore.AddSync(ioutil.Discard),
|
||||
errorOutput: zapcore.AddSync(io.Discard),
|
||||
addStack: zapcore.FatalLevel + 1,
|
||||
clock: zapcore.DefaultClock,
|
||||
}
|
||||
@ -107,6 +107,19 @@ func NewDevelopment(options ...Option) (*Logger, error) {
|
||||
return NewDevelopmentConfig().Build(options...)
|
||||
}
|
||||
|
||||
// Must is a helper that wraps a call to a function returning (*Logger, error)
|
||||
// and panics if the error is non-nil. It is intended for use in variable
|
||||
// initialization such as:
|
||||
//
|
||||
// var logger = zap.Must(zap.NewProduction())
|
||||
func Must(logger *Logger, err error) *Logger {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return logger
|
||||
}
|
||||
|
||||
// NewExample builds a Logger that's designed for use in zap's testable
|
||||
// examples. It writes DebugLevel and above logs to standard out as JSON, but
|
||||
// omits the timestamp and calling function to keep example output
|
||||
@ -177,6 +190,14 @@ func (log *Logger) Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
return log.check(lvl, msg)
|
||||
}
|
||||
|
||||
// Log logs a message at the specified level. The message includes any fields
|
||||
// passed at the log site, as well as any fields accumulated on the logger.
|
||||
func (log *Logger) Log(lvl zapcore.Level, msg string, fields ...Field) {
|
||||
if ce := log.check(lvl, msg); ce != nil {
|
||||
ce.Write(fields...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug logs a message at DebugLevel. The message includes any fields passed
|
||||
// at the log site, as well as any fields accumulated on the logger.
|
||||
func (log *Logger) Debug(msg string, fields ...Field) {
|
||||
@ -285,18 +306,27 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
|
||||
// Set up any required terminal behavior.
|
||||
switch ent.Level {
|
||||
case zapcore.PanicLevel:
|
||||
ce = ce.Should(ent, zapcore.WriteThenPanic)
|
||||
ce = ce.After(ent, zapcore.WriteThenPanic)
|
||||
case zapcore.FatalLevel:
|
||||
onFatal := log.onFatal
|
||||
// Noop is the default value for CheckWriteAction, and it leads to
|
||||
// continued execution after a Fatal which is unexpected.
|
||||
if onFatal == zapcore.WriteThenNoop {
|
||||
// nil or WriteThenNoop will lead to continued execution after
|
||||
// a Fatal log entry, which is unexpected. For example,
|
||||
//
|
||||
// f, err := os.Open(..)
|
||||
// if err != nil {
|
||||
// log.Fatal("cannot open", zap.Error(err))
|
||||
// }
|
||||
// fmt.Println(f.Name())
|
||||
//
|
||||
// The f.Name() will panic if we continue execution after the
|
||||
// log.Fatal.
|
||||
if onFatal == nil || onFatal == zapcore.WriteThenNoop {
|
||||
onFatal = zapcore.WriteThenFatal
|
||||
}
|
||||
ce = ce.Should(ent, onFatal)
|
||||
ce = ce.After(ent, onFatal)
|
||||
case zapcore.DPanicLevel:
|
||||
if log.development {
|
||||
ce = ce.Should(ent, zapcore.WriteThenPanic)
|
||||
ce = ce.After(ent, zapcore.WriteThenPanic)
|
||||
}
|
||||
}
|
||||
|
||||
|
20
vendor/go.uber.org/zap/options.go
generated
vendored
20
vendor/go.uber.org/zap/options.go
generated
vendored
@ -133,9 +133,27 @@ func IncreaseLevel(lvl zapcore.LevelEnabler) Option {
|
||||
}
|
||||
|
||||
// OnFatal sets the action to take on fatal logs.
|
||||
// Deprecated: Use WithFatalHook instead.
|
||||
func OnFatal(action zapcore.CheckWriteAction) Option {
|
||||
return WithFatalHook(action)
|
||||
}
|
||||
|
||||
// WithFatalHook sets a CheckWriteHook to run on fatal logs.
|
||||
// Zap will call this hook after writing a log statement with a Fatal level.
|
||||
//
|
||||
// For example, the following builds a logger that will exit the current
|
||||
// goroutine after writing a fatal log message, but it will not exit the
|
||||
// program.
|
||||
//
|
||||
// zap.New(core, zap.WithFatalHook(zapcore.WriteThenGoexit))
|
||||
//
|
||||
// It is important that the provided CheckWriteHook stops the control flow at
|
||||
// the current statement to meet expectations of callers of the logger.
|
||||
// We recommend calling os.Exit or runtime.Goexit inside custom hooks at
|
||||
// minimum.
|
||||
func WithFatalHook(hook zapcore.CheckWriteHook) Option {
|
||||
return optionFunc(func(log *Logger) {
|
||||
log.onFatal = action
|
||||
log.onFatal = hook
|
||||
})
|
||||
}
|
||||
|
||||
|
116
vendor/go.uber.org/zap/sugar.go
generated
vendored
116
vendor/go.uber.org/zap/sugar.go
generated
vendored
@ -38,10 +38,19 @@ const (
|
||||
// method.
|
||||
//
|
||||
// Unlike the Logger, the SugaredLogger doesn't insist on structured logging.
|
||||
// For each log level, it exposes three methods: one for loosely-typed
|
||||
// structured logging, one for println-style formatting, and one for
|
||||
// printf-style formatting. For example, SugaredLoggers can produce InfoLevel
|
||||
// output with Infow ("info with" structured context), Info, or Infof.
|
||||
// For each log level, it exposes four methods:
|
||||
//
|
||||
// - methods named after the log level for log.Print-style logging
|
||||
// - methods ending in "w" for loosely-typed structured logging
|
||||
// - methods ending in "f" for log.Printf-style logging
|
||||
// - methods ending in "ln" for log.Println-style logging
|
||||
//
|
||||
// For example, the methods for InfoLevel are:
|
||||
//
|
||||
// Info(...any) Print-style logging
|
||||
// Infow(...any) Structured logging (read as "info with")
|
||||
// Infof(string, ...any) Printf-style logging
|
||||
// Infoln(...any) Println-style logging
|
||||
type SugaredLogger struct {
|
||||
base *Logger
|
||||
}
|
||||
@ -61,27 +70,40 @@ func (s *SugaredLogger) Named(name string) *SugaredLogger {
|
||||
return &SugaredLogger{base: s.base.Named(name)}
|
||||
}
|
||||
|
||||
// WithOptions clones the current SugaredLogger, applies the supplied Options,
|
||||
// and returns the result. It's safe to use concurrently.
|
||||
func (s *SugaredLogger) WithOptions(opts ...Option) *SugaredLogger {
|
||||
base := s.base.clone()
|
||||
for _, opt := range opts {
|
||||
opt.apply(base)
|
||||
}
|
||||
return &SugaredLogger{base: base}
|
||||
}
|
||||
|
||||
// With adds a variadic number of fields to the logging context. It accepts a
|
||||
// mix of strongly-typed Field objects and loosely-typed key-value pairs. When
|
||||
// processing pairs, the first element of the pair is used as the field key
|
||||
// and the second as the field value.
|
||||
//
|
||||
// For example,
|
||||
// sugaredLogger.With(
|
||||
// "hello", "world",
|
||||
// "failure", errors.New("oh no"),
|
||||
// Stack(),
|
||||
// "count", 42,
|
||||
// "user", User{Name: "alice"},
|
||||
// )
|
||||
//
|
||||
// sugaredLogger.With(
|
||||
// "hello", "world",
|
||||
// "failure", errors.New("oh no"),
|
||||
// Stack(),
|
||||
// "count", 42,
|
||||
// "user", User{Name: "alice"},
|
||||
// )
|
||||
//
|
||||
// is the equivalent of
|
||||
// unsugared.With(
|
||||
// String("hello", "world"),
|
||||
// String("failure", "oh no"),
|
||||
// Stack(),
|
||||
// Int("count", 42),
|
||||
// Object("user", User{Name: "alice"}),
|
||||
// )
|
||||
//
|
||||
// unsugared.With(
|
||||
// String("hello", "world"),
|
||||
// String("failure", "oh no"),
|
||||
// Stack(),
|
||||
// Int("count", 42),
|
||||
// Object("user", User{Name: "alice"}),
|
||||
// )
|
||||
//
|
||||
// Note that the keys in key-value pairs should be strings. In development,
|
||||
// passing a non-string key panics. In production, the logger is more
|
||||
@ -168,7 +190,8 @@ func (s *SugaredLogger) Fatalf(template string, args ...interface{}) {
|
||||
// pairs are treated as they are in With.
|
||||
//
|
||||
// When debug-level logging is disabled, this is much faster than
|
||||
// s.With(keysAndValues).Debug(msg)
|
||||
//
|
||||
// s.With(keysAndValues).Debug(msg)
|
||||
func (s *SugaredLogger) Debugw(msg string, keysAndValues ...interface{}) {
|
||||
s.log(DebugLevel, msg, nil, keysAndValues)
|
||||
}
|
||||
@ -210,11 +233,48 @@ func (s *SugaredLogger) Fatalw(msg string, keysAndValues ...interface{}) {
|
||||
s.log(FatalLevel, msg, nil, keysAndValues)
|
||||
}
|
||||
|
||||
// Debugln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Debugln(args ...interface{}) {
|
||||
s.logln(DebugLevel, args, nil)
|
||||
}
|
||||
|
||||
// Infoln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Infoln(args ...interface{}) {
|
||||
s.logln(InfoLevel, args, nil)
|
||||
}
|
||||
|
||||
// Warnln uses fmt.Sprintln to construct and log a message.
|
||||
func (s *SugaredLogger) Warnln(args ...interface{}) {
|
||||
s.logln(WarnLevel, args, nil)
|
||||
}
|
||||
|
||||
// Errorln uses fmt.Sprintln to construct and log a message.
|
||||
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.)
|
||||
func (s *SugaredLogger) DPanicln(args ...interface{}) {
|
||||
s.logln(DPanicLevel, args, nil)
|
||||
}
|
||||
|
||||
// Panicln uses fmt.Sprintln to construct and log a message, then panics.
|
||||
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.
|
||||
func (s *SugaredLogger) Fatalln(args ...interface{}) {
|
||||
s.logln(FatalLevel, args, nil)
|
||||
}
|
||||
|
||||
// Sync flushes any buffered log entries.
|
||||
func (s *SugaredLogger) Sync() error {
|
||||
return s.base.Sync()
|
||||
}
|
||||
|
||||
// log message with Sprint, Sprintf, or neither.
|
||||
func (s *SugaredLogger) log(lvl zapcore.Level, template string, fmtArgs []interface{}, context []interface{}) {
|
||||
// If logging at this level is completely disabled, skip the overhead of
|
||||
// string formatting.
|
||||
@ -228,6 +288,18 @@ func (s *SugaredLogger) log(lvl zapcore.Level, template string, fmtArgs []interf
|
||||
}
|
||||
}
|
||||
|
||||
// logln message with Sprintln
|
||||
func (s *SugaredLogger) logln(lvl zapcore.Level, fmtArgs []interface{}, context []interface{}) {
|
||||
if lvl < DPanicLevel && !s.base.Core().Enabled(lvl) {
|
||||
return
|
||||
}
|
||||
|
||||
msg := getMessageln(fmtArgs)
|
||||
if ce := s.base.Check(lvl, msg); ce != nil {
|
||||
ce.Write(s.sweetenFields(context)...)
|
||||
}
|
||||
}
|
||||
|
||||
// getMessage format with Sprint, Sprintf, or neither.
|
||||
func getMessage(template string, fmtArgs []interface{}) string {
|
||||
if len(fmtArgs) == 0 {
|
||||
@ -246,6 +318,12 @@ func getMessage(template string, fmtArgs []interface{}) string {
|
||||
return fmt.Sprint(fmtArgs...)
|
||||
}
|
||||
|
||||
// getMessageln format with Sprintln.
|
||||
func getMessageln(fmtArgs []interface{}) string {
|
||||
msg := fmt.Sprintln(fmtArgs...)
|
||||
return msg[:len(msg)-1]
|
||||
}
|
||||
|
||||
func (s *SugaredLogger) sweetenFields(args []interface{}) []Field {
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
|
9
vendor/go.uber.org/zap/writer.go
generated
vendored
9
vendor/go.uber.org/zap/writer.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
|
||||
@ -23,7 +23,6 @@ package zap
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
@ -71,7 +70,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
for _, path := range paths {
|
||||
sink, err := newSink(path)
|
||||
if err != nil {
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("couldn't open sink %q: %v", path, err))
|
||||
openErr = multierr.Append(openErr, fmt.Errorf("open sink %q: %w", path, err))
|
||||
continue
|
||||
}
|
||||
writers = append(writers, sink)
|
||||
@ -79,7 +78,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
}
|
||||
if openErr != nil {
|
||||
close()
|
||||
return writers, nil, openErr
|
||||
return nil, nil, openErr
|
||||
}
|
||||
|
||||
return writers, close, nil
|
||||
@ -93,7 +92,7 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
||||
// using zapcore.NewMultiWriteSyncer and zapcore.Lock individually.
|
||||
func CombineWriteSyncers(writers ...zapcore.WriteSyncer) zapcore.WriteSyncer {
|
||||
if len(writers) == 0 {
|
||||
return zapcore.AddSync(ioutil.Discard)
|
||||
return zapcore.AddSync(io.Discard)
|
||||
}
|
||||
return zapcore.Lock(zapcore.NewMultiWriteSyncer(writers...))
|
||||
}
|
||||
|
31
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
31
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
@ -43,6 +43,37 @@ const (
|
||||
//
|
||||
// BufferedWriteSyncer is safe for concurrent use. You don't need to use
|
||||
// zapcore.Lock for WriteSyncers with BufferedWriteSyncer.
|
||||
//
|
||||
// To set up a BufferedWriteSyncer, construct a WriteSyncer for your log
|
||||
// destination (*os.File is a valid WriteSyncer), wrap it with
|
||||
// BufferedWriteSyncer, and defer a Stop() call for when you no longer need the
|
||||
// object.
|
||||
//
|
||||
// func main() {
|
||||
// ws := ... // your log destination
|
||||
// bws := &zapcore.BufferedWriteSyncer{WS: ws}
|
||||
// defer bws.Stop()
|
||||
//
|
||||
// // ...
|
||||
// core := zapcore.NewCore(enc, bws, lvl)
|
||||
// logger := zap.New(core)
|
||||
//
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
// By default, a BufferedWriteSyncer will buffer up to 256 kilobytes of logs,
|
||||
// waiting at most 30 seconds between flushes.
|
||||
// You can customize these parameters by setting the Size or FlushInterval
|
||||
// fields.
|
||||
// For example, the following buffers up to 512 kB of logs before flushing them
|
||||
// to Stderr, with a maximum of one minute between each flush.
|
||||
//
|
||||
// ws := &BufferedWriteSyncer{
|
||||
// WS: os.Stderr,
|
||||
// Size: 512 * 1024, // 512 kB
|
||||
// FlushInterval: time.Minute,
|
||||
// }
|
||||
// defer ws.Stop()
|
||||
type BufferedWriteSyncer struct {
|
||||
// WS is the WriteSyncer around which BufferedWriteSyncer will buffer
|
||||
// writes.
|
||||
|
9
vendor/go.uber.org/zap/zapcore/core.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/core.go
generated
vendored
@ -69,6 +69,15 @@ type ioCore struct {
|
||||
out WriteSyncer
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*ioCore)(nil)
|
||||
_ leveledEnabler = (*ioCore)(nil)
|
||||
)
|
||||
|
||||
func (c *ioCore) Level() Level {
|
||||
return LevelOf(c.LevelEnabler)
|
||||
}
|
||||
|
||||
func (c *ioCore) With(fields []Field) Core {
|
||||
clone := c.clone()
|
||||
addFields(clone.enc, fields)
|
||||
|
9
vendor/go.uber.org/zap/zapcore/encoder.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/encoder.go
generated
vendored
@ -188,10 +188,13 @@ func (e *TimeEncoder) UnmarshalText(text []byte) error {
|
||||
|
||||
// UnmarshalYAML unmarshals YAML to a TimeEncoder.
|
||||
// If value is an object with a "layout" field, it will be unmarshaled to TimeEncoder with given layout.
|
||||
// timeEncoder:
|
||||
// layout: 06/01/02 03:04pm
|
||||
//
|
||||
// timeEncoder:
|
||||
// layout: 06/01/02 03:04pm
|
||||
//
|
||||
// If value is string, it uses UnmarshalText.
|
||||
// timeEncoder: iso8601
|
||||
//
|
||||
// timeEncoder: iso8601
|
||||
func (e *TimeEncoder) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var o struct {
|
||||
Layout string `json:"layout" yaml:"layout"`
|
||||
|
71
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
71
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
@ -27,10 +27,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
"go.uber.org/zap/internal/bufferpool"
|
||||
"go.uber.org/zap/internal/exit"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -152,6 +151,27 @@ type Entry struct {
|
||||
Stack string
|
||||
}
|
||||
|
||||
// CheckWriteHook is a custom action that may be executed after an entry is
|
||||
// written.
|
||||
//
|
||||
// Register one on a CheckedEntry with the After method.
|
||||
//
|
||||
// if ce := logger.Check(...); ce != nil {
|
||||
// ce = ce.After(hook)
|
||||
// ce.Write(...)
|
||||
// }
|
||||
//
|
||||
// You can configure the hook for Fatal log statements at the logger level with
|
||||
// the zap.WithFatalHook option.
|
||||
type CheckWriteHook interface {
|
||||
// OnWrite is invoked with the CheckedEntry that was written and a list
|
||||
// of fields added with that entry.
|
||||
//
|
||||
// The list of fields DOES NOT include fields that were already added
|
||||
// to the logger with the With method.
|
||||
OnWrite(*CheckedEntry, []Field)
|
||||
}
|
||||
|
||||
// CheckWriteAction indicates what action to take after a log entry is
|
||||
// processed. Actions are ordered in increasing severity.
|
||||
type CheckWriteAction uint8
|
||||
@ -164,21 +184,36 @@ const (
|
||||
WriteThenGoexit
|
||||
// WriteThenPanic causes a panic after Write.
|
||||
WriteThenPanic
|
||||
// WriteThenFatal causes a fatal os.Exit after Write.
|
||||
// WriteThenFatal causes an os.Exit(1) after Write.
|
||||
WriteThenFatal
|
||||
)
|
||||
|
||||
// OnWrite implements the OnWrite method to keep CheckWriteAction compatible
|
||||
// with the new CheckWriteHook interface which deprecates CheckWriteAction.
|
||||
func (a CheckWriteAction) OnWrite(ce *CheckedEntry, _ []Field) {
|
||||
switch a {
|
||||
case WriteThenGoexit:
|
||||
runtime.Goexit()
|
||||
case WriteThenPanic:
|
||||
panic(ce.Message)
|
||||
case WriteThenFatal:
|
||||
exit.With(1)
|
||||
}
|
||||
}
|
||||
|
||||
var _ CheckWriteHook = CheckWriteAction(0)
|
||||
|
||||
// CheckedEntry is an Entry together with a collection of Cores that have
|
||||
// already agreed to log it.
|
||||
//
|
||||
// CheckedEntry references should be created by calling AddCore or Should on a
|
||||
// CheckedEntry references should be created by calling AddCore or After on a
|
||||
// nil *CheckedEntry. References are returned to a pool after Write, and MUST
|
||||
// NOT be retained after calling their Write method.
|
||||
type CheckedEntry struct {
|
||||
Entry
|
||||
ErrorOutput WriteSyncer
|
||||
dirty bool // best-effort detection of pool misuse
|
||||
should CheckWriteAction
|
||||
after CheckWriteHook
|
||||
cores []Core
|
||||
}
|
||||
|
||||
@ -186,7 +221,7 @@ func (ce *CheckedEntry) reset() {
|
||||
ce.Entry = Entry{}
|
||||
ce.ErrorOutput = nil
|
||||
ce.dirty = false
|
||||
ce.should = WriteThenNoop
|
||||
ce.after = nil
|
||||
for i := range ce.cores {
|
||||
// don't keep references to cores
|
||||
ce.cores[i] = nil
|
||||
@ -224,17 +259,11 @@ func (ce *CheckedEntry) Write(fields ...Field) {
|
||||
ce.ErrorOutput.Sync()
|
||||
}
|
||||
|
||||
should, msg := ce.should, ce.Message
|
||||
putCheckedEntry(ce)
|
||||
|
||||
switch should {
|
||||
case WriteThenPanic:
|
||||
panic(msg)
|
||||
case WriteThenFatal:
|
||||
exit.Exit()
|
||||
case WriteThenGoexit:
|
||||
runtime.Goexit()
|
||||
hook := ce.after
|
||||
if hook != nil {
|
||||
hook.OnWrite(ce, fields)
|
||||
}
|
||||
putCheckedEntry(ce)
|
||||
}
|
||||
|
||||
// AddCore adds a Core that has agreed to log this CheckedEntry. It's intended to be
|
||||
@ -252,11 +281,19 @@ 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.
|
||||
func (ce *CheckedEntry) Should(ent Entry, should CheckWriteAction) *CheckedEntry {
|
||||
return ce.After(ent, should)
|
||||
}
|
||||
|
||||
// After sets this CheckEntry's CheckWriteHook, which will be called after this
|
||||
// log entry has been written. It's safe to call this on nil CheckedEntry
|
||||
// references.
|
||||
func (ce *CheckedEntry) After(ent Entry, hook CheckWriteHook) *CheckedEntry {
|
||||
if ce == nil {
|
||||
ce = getCheckedEntry()
|
||||
ce.Entry = ent
|
||||
}
|
||||
ce.should = should
|
||||
ce.after = hook
|
||||
return ce
|
||||
}
|
||||
|
14
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
14
vendor/go.uber.org/zap/zapcore/error.go
generated
vendored
@ -36,13 +36,13 @@ import (
|
||||
// causer (from github.com/pkg/errors), a ${key}Causes field is added with an
|
||||
// array of objects containing the errors this error was comprised of.
|
||||
//
|
||||
// {
|
||||
// "error": err.Error(),
|
||||
// "errorVerbose": fmt.Sprintf("%+v", err),
|
||||
// "errorCauses": [
|
||||
// ...
|
||||
// ],
|
||||
// }
|
||||
// {
|
||||
// "error": err.Error(),
|
||||
// "errorVerbose": fmt.Sprintf("%+v", err),
|
||||
// "errorCauses": [
|
||||
// ...
|
||||
// ],
|
||||
// }
|
||||
func encodeError(key string, err error, enc ObjectEncoder) (retErr error) {
|
||||
// Try to capture panics (from nil references or otherwise) when calling
|
||||
// the Error() method
|
||||
|
9
vendor/go.uber.org/zap/zapcore/hook.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/hook.go
generated
vendored
@ -27,6 +27,11 @@ type hooked struct {
|
||||
funcs []func(Entry) error
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*hooked)(nil)
|
||||
_ leveledEnabler = (*hooked)(nil)
|
||||
)
|
||||
|
||||
// RegisterHooks wraps a Core and runs a collection of user-defined callback
|
||||
// hooks each time a message is logged. Execution of the callbacks is blocking.
|
||||
//
|
||||
@ -40,6 +45,10 @@ func RegisterHooks(core Core, hooks ...func(Entry) error) Core {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *hooked) Level() Level {
|
||||
return LevelOf(h.Core)
|
||||
}
|
||||
|
||||
func (h *hooked) Check(ent Entry, ce *CheckedEntry) *CheckedEntry {
|
||||
// Let the wrapped Core decide whether to log this message or not. This
|
||||
// also gives the downstream a chance to register itself directly with the
|
||||
|
9
vendor/go.uber.org/zap/zapcore/increase_level.go
generated
vendored
9
vendor/go.uber.org/zap/zapcore/increase_level.go
generated
vendored
@ -27,6 +27,11 @@ type levelFilterCore struct {
|
||||
level LevelEnabler
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*levelFilterCore)(nil)
|
||||
_ leveledEnabler = (*levelFilterCore)(nil)
|
||||
)
|
||||
|
||||
// NewIncreaseLevelCore creates a core that can be used to increase the level of
|
||||
// an existing Core. It cannot be used to decrease the logging level, as it acts
|
||||
// as a filter before calling the underlying core. If level decreases the log level,
|
||||
@ -45,6 +50,10 @@ func (c *levelFilterCore) Enabled(lvl Level) bool {
|
||||
return c.level.Enabled(lvl)
|
||||
}
|
||||
|
||||
func (c *levelFilterCore) Level() Level {
|
||||
return LevelOf(c.level)
|
||||
}
|
||||
|
||||
func (c *levelFilterCore) With(fields []Field) Core {
|
||||
return &levelFilterCore{c.core.With(fields), c.level}
|
||||
}
|
||||
|
4
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
4
vendor/go.uber.org/zap/zapcore/json_encoder.go
generated
vendored
@ -71,7 +71,9 @@ type jsonEncoder struct {
|
||||
//
|
||||
// Note that the encoder doesn't deduplicate keys, so it's possible to produce
|
||||
// a message like
|
||||
// {"foo":"bar","foo":"baz"}
|
||||
//
|
||||
// {"foo":"bar","foo":"baz"}
|
||||
//
|
||||
// This is permitted by the JSON specification, but not encouraged. Many
|
||||
// libraries will ignore duplicate key-value pairs (typically keeping the last
|
||||
// pair) when unmarshaling, but users should attempt to avoid adding duplicate
|
||||
|
42
vendor/go.uber.org/zap/zapcore/level.go
generated
vendored
42
vendor/go.uber.org/zap/zapcore/level.go
generated
vendored
@ -53,6 +53,11 @@ const (
|
||||
|
||||
_minLevel = DebugLevel
|
||||
_maxLevel = FatalLevel
|
||||
|
||||
// InvalidLevel is an invalid value for Level.
|
||||
//
|
||||
// Core implementations may panic if they see messages of this level.
|
||||
InvalidLevel = _maxLevel + 1
|
||||
)
|
||||
|
||||
// ParseLevel parses a level based on the lower-case or all-caps ASCII
|
||||
@ -67,6 +72,43 @@ func ParseLevel(text string) (Level, error) {
|
||||
return level, err
|
||||
}
|
||||
|
||||
type leveledEnabler interface {
|
||||
LevelEnabler
|
||||
|
||||
Level() Level
|
||||
}
|
||||
|
||||
// LevelOf reports the minimum enabled log level for the given LevelEnabler
|
||||
// from Zap's supported log levels, or [InvalidLevel] if none of them are
|
||||
// enabled.
|
||||
//
|
||||
// A LevelEnabler may implement a 'Level() Level' method to override the
|
||||
// behavior of this function.
|
||||
//
|
||||
// func (c *core) Level() Level {
|
||||
// return c.currentLevel
|
||||
// }
|
||||
//
|
||||
// It is recommended that [Core] implementations that wrap other cores use
|
||||
// LevelOf to retrieve the level of the wrapped core. For example,
|
||||
//
|
||||
// func (c *coreWrapper) Level() Level {
|
||||
// return zapcore.LevelOf(c.wrappedCore)
|
||||
// }
|
||||
func LevelOf(enab LevelEnabler) Level {
|
||||
if lvler, ok := enab.(leveledEnabler); ok {
|
||||
return lvler.Level()
|
||||
}
|
||||
|
||||
for lvl := _minLevel; lvl <= _maxLevel; lvl++ {
|
||||
if enab.Enabled(lvl) {
|
||||
return lvl
|
||||
}
|
||||
}
|
||||
|
||||
return InvalidLevel
|
||||
}
|
||||
|
||||
// String returns a lower-case ASCII representation of the log level.
|
||||
func (l Level) String() string {
|
||||
switch l {
|
||||
|
25
vendor/go.uber.org/zap/zapcore/sampler.go
generated
vendored
25
vendor/go.uber.org/zap/zapcore/sampler.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
|
||||
@ -113,12 +113,12 @@ func nopSamplingHook(Entry, SamplingDecision) {}
|
||||
// This hook may be used to get visibility into the performance of the sampler.
|
||||
// For example, use it to track metrics of dropped versus sampled logs.
|
||||
//
|
||||
// var dropped atomic.Int64
|
||||
// zapcore.SamplerHook(func(ent zapcore.Entry, dec zapcore.SamplingDecision) {
|
||||
// if dec&zapcore.LogDropped > 0 {
|
||||
// dropped.Inc()
|
||||
// }
|
||||
// })
|
||||
// var dropped atomic.Int64
|
||||
// zapcore.SamplerHook(func(ent zapcore.Entry, dec zapcore.SamplingDecision) {
|
||||
// if dec&zapcore.LogDropped > 0 {
|
||||
// dropped.Inc()
|
||||
// }
|
||||
// })
|
||||
func SamplerHook(hook func(entry Entry, dec SamplingDecision)) SamplerOption {
|
||||
return optionFunc(func(s *sampler) {
|
||||
s.hook = hook
|
||||
@ -135,7 +135,7 @@ func SamplerHook(hook func(entry Entry, dec SamplingDecision)) SamplerOption {
|
||||
//
|
||||
// For example,
|
||||
//
|
||||
// core = NewSamplerWithOptions(core, time.Second, 10, 5)
|
||||
// core = NewSamplerWithOptions(core, time.Second, 10, 5)
|
||||
//
|
||||
// This will log the first 10 log entries with the same level and message
|
||||
// in a one second interval as-is. Following that, it will allow through
|
||||
@ -175,6 +175,11 @@ type sampler struct {
|
||||
hook func(Entry, SamplingDecision)
|
||||
}
|
||||
|
||||
var (
|
||||
_ Core = (*sampler)(nil)
|
||||
_ leveledEnabler = (*sampler)(nil)
|
||||
)
|
||||
|
||||
// NewSampler creates a Core that samples incoming entries, which
|
||||
// caps the CPU and I/O load of logging while attempting to preserve a
|
||||
// representative subset of your logs.
|
||||
@ -192,6 +197,10 @@ func NewSampler(core Core, tick time.Duration, first, thereafter int) Core {
|
||||
return NewSamplerWithOptions(core, tick, first, thereafter)
|
||||
}
|
||||
|
||||
func (s *sampler) Level() Level {
|
||||
return LevelOf(s.Core)
|
||||
}
|
||||
|
||||
func (s *sampler) With(fields []Field) Core {
|
||||
return &sampler{
|
||||
Core: s.Core.With(fields),
|
||||
|
17
vendor/go.uber.org/zap/zapcore/tee.go
generated
vendored
17
vendor/go.uber.org/zap/zapcore/tee.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
|
||||
@ -24,6 +24,11 @@ import "go.uber.org/multierr"
|
||||
|
||||
type multiCore []Core
|
||||
|
||||
var (
|
||||
_ leveledEnabler = multiCore(nil)
|
||||
_ Core = multiCore(nil)
|
||||
)
|
||||
|
||||
// NewTee creates a Core that duplicates log entries into two or more
|
||||
// underlying Cores.
|
||||
//
|
||||
@ -48,6 +53,16 @@ func (mc multiCore) With(fields []Field) Core {
|
||||
return clone
|
||||
}
|
||||
|
||||
func (mc multiCore) Level() Level {
|
||||
minLvl := _maxLevel // mc is never empty
|
||||
for i := range mc {
|
||||
if lvl := LevelOf(mc[i]); lvl < minLvl {
|
||||
minLvl = lvl
|
||||
}
|
||||
}
|
||||
return minLvl
|
||||
}
|
||||
|
||||
func (mc multiCore) Enabled(lvl Level) bool {
|
||||
for i := range mc {
|
||||
if mc[i].Enabled(lvl) {
|
||||
|
Reference in New Issue
Block a user