package zapr
import "github.com/go-logr/zapr"
Package zapr defines an implementation of the github.com/go-logr/logr interfaces built on top of Zap (go.uber.org/zap).
Usage
A new logr.Logger can be constructed from an existing zap.Logger using the NewLogger function:
log := zapr.NewLogger(someZapLogger)
Implementation Details
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 log methods.
Levels in logr correspond to custom debug levels in Zap. Any given level in logr is represents by its inverse in zap (`zapLevel = -1*logrLevel`). For example V(2) is equivalent to log level -2 in Zap, while V(1) is equivalent to Zap's DebugLevel.
Index ¶
- func NewLogger(l *zap.Logger) logr.Logger
- func NewLoggerWithOptions(l *zap.Logger, opts ...Option) logr.Logger
- type Option
- func AllowZapFields(allowed bool) Option
- func DPanicOnBugs(enabled bool) Option
- func ErrorKey(key string) Option
- func LogInfoLevel(key string) Option
- type Underlier
Functions ¶
func NewLogger ¶
NewLogger creates a new logr.Logger using the given Zap Logger to log.
func NewLoggerWithOptions ¶
NewLoggerWithOptions creates a new logr.Logger using the given Zap Logger to log and applies additional options.
Types ¶
type Option ¶
type Option func(*zapLogger)
Option is one additional parameter for NewLoggerWithOptions.
func AllowZapFields ¶
AllowZapFields controls whether strongly-typed Zap fields may be passed instead of a key/value pair. This is disabled by default because it breaks implementation agnosticism.
func DPanicOnBugs ¶
DPanicOnBugs controls whether extra log messages are emitted for invalid log calls with zap's DPanic method. Depending on the configuration of the zap logger, the program then panics after emitting the log message which is useful in development because such invalid log calls are bugs in the program. The log messages explain why a call was invalid (for example, non-string key). Emitting them is enabled by default.
func ErrorKey ¶
ErrorKey replaces the default "error" field name used for the error in Logger.Error calls.
func LogInfoLevel ¶
LogInfoLevel controls whether a numeric log level is added to Info log message. The empty string disables this, a non-empty string is the key for the additional field. Errors and internal panic messages do not have a log level and thus are always logged without this extra field.
type Underlier ¶
Underlier exposes access to the underlying logging implementation. Since callers only have a logr.Logger, they have to know which implementation is in use, so this interface is less of an abstraction and more of way to test type conversion.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example |
- Version
- v1.1.0
- Published
- Aug 24, 2021
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- now –
Tools for package owners.