zap

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 5 Imported by: 0

README

zap

Using zap instance to build a logger.Logger

// there are few ways to build a zap instance

// using the logger configuration
var log, flush, err = zap.New(
    zap.WithConfig(cfg logger.Config),
)

// building it directly
var log, flush, err = zap.New(
    logrus.WithLevel(level logger.Level),
    logrus.WithConsoleFormatter(colored bool),
    logrus.WithJSONFormatter(),
    logrus.WithOutputPaths(output []string),
)

// or by giving an original zap.Config
var log, flush, err = zap.New(
    logrus.WithZapConfig(cfg zap.Config),
)

Once the logger has been built, it can be used like any other logger.Logger.

Documentation

Overview

Package zap implements the logger.Logger interface using uber/zap implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) (logger.Logger, func() error, error)

New returns a new zap instance.

Types

type Option

type Option func(*config) error

Option defines a function signature to update configuration.

func WithConfig

func WithConfig(cfg logger.Config) Option

WithConfig takes the logger configuration and applies it.

func WithConsoleFormatter

func WithConsoleFormatter(colored bool) Option

WithConsoleFormatter configures the format of the log output

to use "console" (cli) formatter.

func WithJSONFormatter

func WithJSONFormatter() Option

WithJSONFormatter configures the format of the log output

to use "json" formatter.

func WithLevel

func WithLevel(level logger.Level) Option

WithLevel configures the minimum level of the logger. It can late be updated with SetLevel.

func WithOutputPaths

func WithOutputPaths(paths []string) Option

WithOutputPaths configures the paths used to write logs to.

To use standart output, and error output, use stdout or stderr.

func WithZapConfig

func WithZapConfig(cfg zap.Config) Option

WithZapConfig applies zap configuration directly into the configuration.

func WithoutTime added in v1.2.0

func WithoutTime() Option

WithoutTime configures the logger to log without time.

type Zap

type Zap struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

Zap implements Logger interface.

func (*Zap) SetLevel

func (l *Zap) SetLevel(level logger.Level) error

SetLevel applies a new level to a logger instance.

func (*Zap) WithError

func (l *Zap) WithError(err error) logger.Logger

WithError implements Logger.WithError for Zap logger.

func (*Zap) WithField

func (l *Zap) WithField(key string, value interface{}) logger.Logger

WithField implements Logger.WithField for Zap logger.

func (*Zap) WithFields

func (l *Zap) WithFields(fields map[string]interface{}) logger.Logger

WithFields implements Logger.WithFields for Zap logger.

Jump to

Keyboard shortcuts

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