logger

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

func Errorw

func Errorw(msg string, err error, keysAndValues ...interface{})

func Infow

func Infow(msg string, keysAndValues ...interface{})

func InitFromConfig

func InitFromConfig(conf *Config, name string)

InitFromConfig initializes a Zap-based logger

func NewFieldSampler

func NewFieldSampler(core zapcore.Core, config FieldSamplerConfig) zapcore.Core

func ParseZapLevel

func ParseZapLevel(level string) zapcore.Level

func Proto

func SetLogger

func SetLogger(l Logger, name string)

SetLogger lets you use a custom logger. Pass in a logr.Logger with default depth

func Warnw

func Warnw(msg string, err error, keysAndValues ...interface{})

Types

type AtomicFieldSampleRate

type AtomicFieldSampleRate uint64

func NewAtomicFieldSampleRate

func NewAtomicFieldSampleRate(rate float64) *AtomicFieldSampleRate

func (*AtomicFieldSampleRate) SetRate

func (r *AtomicFieldSampleRate) SetRate(rate float64)

func (*AtomicFieldSampleRate) Threshold

func (r *AtomicFieldSampleRate) Threshold() uint64

type Config

type Config struct {
	JSON  bool   `yaml:"json,omitempty"`
	Level string `yaml:"level,omitempty"`
	// true to enable log sampling, where the same log message and level will be throttled.
	// we have two layers of sampling
	// 1. global sampling - within a second, it will log the first SampleInitial, then every SampleInterval messages.
	// 2. per participant/track sampling - to be used with Logger.WithItemSampler(). This would be used to throttle
	//    the logs for a particular participant/track.
	Sample bool `yaml:"sample,omitempty"`

	ComponentLevels map[string]string `yaml:"component_levels,omitempty"`

	// global sampling per server
	// when sampling, the first N logs will be logged
	SampleInitial int `yaml:"sample_initial,omitempty"`
	// when sampling, every Mth log will be logged
	SampleInterval int `yaml:"sample_interval,omitempty"`

	// participant/track level sampling
	ItemSampleSeconds  int `yaml:"item_sample_seconds,omitempty"`
	ItemSampleInitial  int `yaml:"item_sample_initial,omitempty"`
	ItemSampleInterval int `yaml:"item_sample_interval,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) AddUpdateObserver

func (c *Config) AddUpdateObserver(cb ConfigObserver)

func (*Config) Update

func (c *Config) Update(o *Config) error

type ConfigObserver

type ConfigObserver func(*Config) error

type FieldSampleRate

type FieldSampleRate interface {
	Threshold() uint64
}

type FieldSamplerAction

type FieldSamplerAction int
const (
	OmitSampledLog FieldSamplerAction = iota
	AnnotateSampledLog
)

type FieldSamplerConfig

type FieldSamplerConfig struct {
	FieldName           string
	Rate                FieldSampleRate
	Action              FieldSamplerAction
	AnnotationFieldName string
}

type LogRLogger

type LogRLogger logr.Logger

func (LogRLogger) Debugw

func (l LogRLogger) Debugw(msg string, keysAndValues ...interface{})

func (LogRLogger) Errorw

func (l LogRLogger) Errorw(msg string, err error, keysAndValues ...interface{})

func (LogRLogger) Infow

func (l LogRLogger) Infow(msg string, keysAndValues ...interface{})

func (LogRLogger) Warnw

func (l LogRLogger) Warnw(msg string, err error, keysAndValues ...interface{})

func (LogRLogger) WithCallDepth

func (l LogRLogger) WithCallDepth(depth int) Logger

func (LogRLogger) WithComponent

func (l LogRLogger) WithComponent(component string) Logger

func (LogRLogger) WithItemSampler

func (l LogRLogger) WithItemSampler() Logger

func (LogRLogger) WithName

func (l LogRLogger) WithName(name string) Logger

func (LogRLogger) WithValues

func (l LogRLogger) WithValues(keysAndValues ...interface{}) Logger

func (LogRLogger) WithoutSampler

func (l LogRLogger) WithoutSampler() Logger

type Logger

type Logger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, err error, keysAndValues ...interface{})
	Errorw(msg string, err error, keysAndValues ...interface{})
	WithValues(keysAndValues ...interface{}) Logger
	WithName(name string) Logger
	// WithComponent creates a new logger with name as "<name>.<component>", and uses a log level as specified
	WithComponent(component string) Logger
	WithCallDepth(depth int) Logger
	WithItemSampler() Logger
	// WithoutSampler returns the original logger without sampling
	WithoutSampler() Logger
}

func GetLogger

func GetLogger() Logger

GetLogger returns the logger that was set with SetLogger with an extra depth of 1

type ZapLogger

type ZapLogger struct {
	SampleDuration time.Duration
	SampleInitial  int
	SampleInterval int
	// contains filtered or unexported fields
}

func NewZapLogger

func NewZapLogger(conf *Config) (*ZapLogger, error)

func (*ZapLogger) Debugw

func (l *ZapLogger) Debugw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Errorw

func (l *ZapLogger) Errorw(msg string, err error, keysAndValues ...interface{})

func (*ZapLogger) Infow

func (l *ZapLogger) Infow(msg string, keysAndValues ...interface{})

func (*ZapLogger) ToZap

func (l *ZapLogger) ToZap() *zap.SugaredLogger

func (*ZapLogger) Warnw

func (l *ZapLogger) Warnw(msg string, err error, keysAndValues ...interface{})

func (*ZapLogger) WithCallDepth

func (l *ZapLogger) WithCallDepth(depth int) Logger

func (*ZapLogger) WithComponent

func (l *ZapLogger) WithComponent(component string) Logger

func (*ZapLogger) WithFieldSampler

func (l *ZapLogger) WithFieldSampler(config FieldSamplerConfig) *ZapLogger

func (*ZapLogger) WithItemSampler

func (l *ZapLogger) WithItemSampler() Logger

func (*ZapLogger) WithName

func (l *ZapLogger) WithName(name string) Logger

func (*ZapLogger) WithValues

func (l *ZapLogger) WithValues(keysAndValues ...interface{}) Logger

func (*ZapLogger) WithoutSampler

func (l *ZapLogger) WithoutSampler() Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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