https://github.com/binaryphile/zerologr
A logr implementation using Zerolog
https://github.com/binaryphile/zerologr
Last synced: 5 months ago
JSON representation
A logr implementation using Zerolog
- Host: GitHub
- URL: https://github.com/binaryphile/zerologr
- Owner: binaryphile
- License: apache-2.0
- Fork: true (go-logr/zerologr)
- Created: 2022-12-14T02:52:08.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-23T20:49:15.000Z (over 3 years ago)
- Last Synced: 2024-06-20T17:34:22.447Z (about 2 years ago)
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zerologr
[](https://pkg.go.dev/github.com/go-logr/zerologr)

[](https://goreportcard.com/report/github.com/go-logr/zerologr)
A [logr](https://github.com/go-logr/logr) LogSink implementation using [Zerolog](https://github.com/rs/zerolog).
## Usage
```go
import (
"os"
"github.com/go-logr/logr"
"github.com/go-logr/zerologr"
"github.com/rs/zerolog"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
zerologr.NameFieldName = "logger"
zerologr.NameSeparator = "/"
zl := zerolog.New(os.Stderr)
zl = zl.With().Caller().Timestamp().Logger()
var log logr.Logger = zerologr.New(&zl)
log.Info("Logr in action!", "the answer", 42)
}
```
## Implementation Details
For the most part, concepts in Zerolog correspond directly with those in logr.
Levels in logr correspond to custom debug levels in Zerolog. Any given level
in logr is represents by `zerologLevel = 1 - logrLevel`.
For example `V(2)` is equivalent to Zerolog's `TraceLevel`, while `V(1)` is
equivalent to Zerolog's `DebugLevel`.