zapr

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2021 License: BSD-3-Clause Imports: 14 Imported by: 3

README

Zapr

License GoDev Reference Go Report Card

Zapr provides a logr.Logger interface around a zap implementation, including metrics and a standard library log.Logger adapter.

Documentation

Overview

Package zapr provides a logr.Logger interface around a zap implementation, including metrics and a standard library log.Logger adapter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStdErrorLogger

func NewStdErrorLogger(logger logr.CallDepthLogger) *log.Logger

NewStdErrorLogger returns a *log.Logger which writes to the supplied Logger's Error method.

func NewStdInfoLogger

func NewStdInfoLogger(logger logr.CallDepthLogger) *log.Logger

NewStdInfoLogger returns a *log.Logger which writes to the supplied Logger's Info method.

Types

type Config

type Config struct {
	Name  string
	Level int

	TimeKey       string
	LevelKey      string
	NameKey       string
	CallerKey     string
	FunctionKey   string
	MessageKey    string
	ErrorKey      string
	StacktraceKey string
	LineEnding    string

	Encoder         encoding.Encoder
	TimeEncoder     encoding.TimeEncoder
	LevelEncoder    encoding.LevelEncoder
	DurationEncoder encoding.DurationEncoder
	CallerEncoder   encoding.CallerEncoder

	EnableStacktrace bool
	EnableCaller     bool
	Development      bool

	SampleInitial    int
	SampleThereafter int

	Metrics Metrics
}

Config specifies the configuration of a Logger.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default Config.

func DevelopmentConfig

func DevelopmentConfig() *Config

DevelopmentConfig returns a development-friendly Config.

func (*Config) RegisterCommonFlags

func (c *Config) RegisterCommonFlags(fs *flag.FlagSet) *Config

RegisterCommonFlags registers basic fields of the Config as flags in the FlagSet. If fs is nil, flag.CommandLine is used.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(fs *flag.FlagSet) *Config

RegisterFlags registers fields of the Config as flags in the FlagSet. If fs is nil, flag.CommandLine is used.

type Logger

type Logger interface {
	// This is the main logging interface. All methods that return a logr.Logger
	// (e.g. V, WithValues, WithName, WithCallDepth) will return a value implementing
	// zapr.Logger (e.g. with the additional Underlying and Flush methods).
	logr.CallDepthLogger

	// Underlying returns the underlying *zap.Logger with no caller skips.
	// It may return nil if the logger is disabled.
	Underlying() *zap.Logger

	// Flush writes any buffered data to the underlying io.Writer.
	Flush() error
}

Logger represents the ability to log messages, both errors and not.

func NewLogger

func NewLogger(c *Config) Logger

NewLogger creates a new Logger with the given Config.

func Noop

func Noop() Logger

Noop returns a disabled Logger for which all operations are no-op.

type Metrics

type Metrics interface {
	// Init initializes metrics for the named logger when it's created.
	// Logger names are not required to be unique and it may be called
	// with a duplicate name at any time.
	Init(logger string)

	// ObserveEntryLogged observes logged entry metrics for the named logger, at
	// the given level, and with the given bytes.
	ObserveEntryLogged(logger string, level string, bytes int)

	// ObserveEncoderError observes an error encoding an entry for the named logger.
	ObserveEncoderError(logger string)
}

Metrics represent the ability to observe log metrics.

Directories

Path Synopsis
Package encoding provides named encoders with flag integration.
Package encoding provides named encoders with flag integration.
Package zaprprom provides a Prometheus metrics implementation for zapr.
Package zaprprom provides a Prometheus metrics implementation for zapr.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL