dependencies: zapr v1.3.0, zap v1.26.0

The new zapr adds support for slog. The new zap has various improvements. It no
longer depends on go.uber.org/atomic which enables dropping it from the
Kubernetes dependencies. github.com/pkg/errors is also no longer needed.
This commit is contained in:
Patrick Ohly
2023-11-07 11:31:45 +01:00
parent 246d363ea4
commit 166b71757b
112 changed files with 2517 additions and 2988 deletions

View File

@@ -2,12 +2,17 @@ Zapr :zap:
==========
A [logr](https://github.com/go-logr/logr) implementation using
[Zap](https://github.com/uber-go/zap).
[Zap](https://github.com/uber-go/zap). Can also be used as
[slog](https://pkg.go.dev/log/slog) handler.
Usage
-----
Via logr:
```go
package main
import (
"fmt"
@@ -29,6 +34,33 @@ func main() {
}
```
Via slog:
```
package main
import (
"fmt"
"log/slog"
"github.com/go-logr/logr/slogr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
)
func main() {
var log *slog.Logger
zapLog, err := zap.NewDevelopment()
if err != nil {
panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
}
log = slog.New(slogr.NewSlogHandler(zapr.NewLogger(zapLog)))
log.Info("Logr in action!", "the answer", 42)
}
```
Increasing Verbosity
--------------------
@@ -68,3 +100,8 @@ For the most part, concepts in Zap correspond directly with those in logr.
Unlike Zap, all fields *must* be in the form of sugared fields --
it's illegal to pass a strongly-typed Zap field in a key position to any
of the logging methods (`Log`, `Error`).
The zapr `logr.LogSink` implementation also implements `logr.SlogHandler`. That
enables `slogr.NewSlogHandler` to provide a `slog.Handler` which just passes
parameters through to zapr. zapr handles special slog values (Group,
LogValuer), regardless of which front-end API is used.