logger

package
v0.0.0-...-8993a07 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	EncodingConsole bool   `env:"ENCODING_CONSOLE" default:"false" usage:"allows to set user-friendly formatting"`
	Level           string `env:"LEVEL" default:"info" usage:"allows to set custom logger level"`
	Trace           string `env:"TRACE" default:"fatal" usage:"allows to set custom trace level"`
	SampleRate      *int   `env:"SAMPLE_RATE" default:"1000" usage:"allows to set sample rate"`
}

Config structure that provides configuration of logger module.

func (*Config) Validate

func (c *Config) Validate(_ context.Context) error

Validate we should check that passed configuration is valid, so: - trace and level should be empty or valid logger level - sample rate should be empty or greater than zero.

type Logger

type Logger interface {
	Debug(...interface{})
	Debugf(msg string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})

	Info(...interface{})
	Infof(msg string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Warn(...interface{})
	Warnf(msg string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})

	Error(...interface{})
	Errorf(msg string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})

	Fatal(...interface{})
	Fatalf(msg string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	Panic(...interface{})
	Panicf(msg string, args ...interface{})
	Panicw(msg string, keysAndValues ...interface{})

	With(...interface{}) Logger

	Named(string) Logger

	Sugar() *SugaredLogger

	Std() *log.Logger

	Sync() error
}

Logger common interface.

func Default

func Default() Logger

Default returns default logger instance.

func ForTests

func ForTests(t testingT) Logger

ForTests wrapped logger for tests.

func New

func New(cfg Config, opts ...Option) (Logger, error)

New prepares logger module.

type Option

type Option func(*logger)

Option allows to set custom logger settings.

func WithAppName

func WithAppName(v string) Option

WithAppName allows to set application name to logger fields.

func WithAppVersion

func WithAppVersion(v string) Option

WithAppVersion allows to set application version to logger fields.

func WithConsoleColored

func WithConsoleColored() Option

WithConsoleColored allows to set colored console output.

func WithCustomLevel

func WithCustomLevel(v zap.AtomicLevel) Option

WithCustomLevel allows to pass custom level, that can be changed at any time. For example take a look https://github.com/uber-go/zap/blob/master/http_handler.go#L33.

func WithCustomOutput

func WithCustomOutput(name string, v Sink) Option

WithCustomOutput allows to set custom output for Logger.

func WithTimeKey

func WithTimeKey(v string) Option

WithTimeKey allows to set TimeKey for zapcore.EncoderConfig.

func WithZapOption

func WithZapOption(v zap.Option) Option

WithZapOption allows to set zap.Option.

type Sink

type Sink = zap.Sink

Sink defines the interface to write to and close logger destinations. Type alias.

type SugaredLogger

type SugaredLogger = zap.SugaredLogger

A SugaredLogger wraps the base Logger functionality in a slower, but less verbose, API. Any Logger can be converted to a SugaredLogger with its Sugar method. Type alias.

type WriteSyncer

type WriteSyncer = zapcore.WriteSyncer

WriteSyncer is an io.Writer that can also flush any buffered data. Note that *os.File (and thus, os.Stderr and os.Stdout) implement WriteSyncer. Type alias.

Jump to

Keyboard shortcuts

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