logger

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLevel         = InfoLevel
	DefaultFlushInterval = time.Duration(3) * time.Second
)

Variables

View Source
var (
	NewDevelopmentConfig = zap.NewDevelopmentConfig
	NewProductionConfig  = zap.NewProductionConfig
	NewAtomicLevelAt     = zap.NewAtomicLevelAt
)
View Source
var (
	NewConsoleEncoder = zapcore.NewConsoleEncoder
	NewJSONEncoder    = zapcore.NewJSONEncoder
)
View Source
var (
	NewDevelopmentEncoderConfig = zap.NewDevelopmentEncoderConfig
	NewProductionEncoderConfig  = zap.NewProductionEncoderConfig
)
View Source
var ErrFilterOutExistsForKey = errors.New("filter-out key already exists in filter")

ErrFilterOutExistsForKey must be returned when a filter-out already exists for a given key.

Functions

func Debugw

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

func Errorw

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

func Fatalw

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

func Infow

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

func Init

func Init(cfg LoggingConfig)

Init sets the package-level base logger using given config It's not thread safe so if required use it always at the beginning

func Log

func Log(lvl Level, innerAggregation bool, msg string, keysAndValues ...interface{})

Log is a generic helper that allows logging by choosing the desired level and if the aggregation should be done. It does NOT override those options. For the case where innerAggregation is set to true, it will only aggregate if pkg logger's aggregation config is also set to true.

func SetLevel added in v0.20.0

func SetLevel(level Level)

SetLevel sets package-level base logger level, it is threadsafe

func SetLogger

func SetLogger(l LoggerInterface)

SetLogger sets package-level base logger

func Warnw

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

Types

type AtomicLevel added in v0.20.0

type AtomicLevel = zap.AtomicLevel

type Config

type Config = zap.Config

type Encoder

type Encoder = zapcore.Encoder

type EncoderConfig

type EncoderConfig = zapcore.EncoderConfig

type FilterKind

type FilterKind int

FilterKind is used to specify whether a filter should be applied to logs that match the filter or logs that do not match the filter.

const (
	FilterIn FilterKind = iota
	FilterOut
)

FilterKind values

type Level

type Level = zapcore.Level
const (
	DebugLevel  Level = zap.DebugLevel
	InfoLevel   Level = zap.InfoLevel
	WarnLevel   Level = zap.WarnLevel
	ErrorLevel  Level = zap.ErrorLevel
	DPanicLevel Level = zap.DPanicLevel
	PanicLevel  Level = zap.PanicLevel
	FatalLevel  Level = zap.FatalLevel
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger struct

func Current

func Current() *Logger

Current returns the package-level base logger

func (*Logger) Debugw

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

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, keysAndValues ...interface{})

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, keysAndValues ...interface{})

func (*Logger) Infow

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

func (*Logger) Sync

func (l *Logger) Sync() error

Sync

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, keysAndValues ...interface{})

type LoggerConfig

type LoggerConfig struct {
	Writer  io.Writer
	Level   AtomicLevel
	Encoder Encoder
}

LoggerConfig defines the configuration parameters for constructing tracker's logger implementation. Logger user AtomicLevel to allow changing the logging level at runtime.

func NewDefaultLoggerConfig

func NewDefaultLoggerConfig() LoggerConfig

type LoggerFilter

type LoggerFilter struct {
	// contains filtered or unexported fields
}

LoggerFilter is used to filter logs.

func NewLoggerFilter

func NewLoggerFilter() LoggerFilter

NewLoggerFilter creates a new LoggerFilter.

func (*LoggerFilter) AddFile

func (lf *LoggerFilter) AddFile(s string, t FilterKind) error

AddFile adds a filter value and type to be checked against file names.

func (*LoggerFilter) AddLvl

func (lf *LoggerFilter) AddLvl(i int, t FilterKind) error

AddLvl adds a filter value and type to be checked against log levels.

func (*LoggerFilter) AddMsg

func (lf *LoggerFilter) AddMsg(s string, t FilterKind) error

AddMsg adds a filter value and type to be checked against messages.

func (*LoggerFilter) AddMsgRegex

func (lf *LoggerFilter) AddMsgRegex(regex string, t FilterKind) error

AddMsgRegex adds a filter regex and type to be checked against messages.

func (*LoggerFilter) AddPkg

func (lf *LoggerFilter) AddPkg(s string, t FilterKind) error

AddPkg adds a filter value and type to be checked against package names.

func (*LoggerFilter) Enabled

func (lf *LoggerFilter) Enabled() bool

Enabled returns true if any filters are enabled.

type LoggerInterface

type LoggerInterface interface {
	Debugw(msg string, keyAndValues ...interface{})
	Infow(msg string, keyAndValues ...interface{})
	Warnw(msg string, keyAndValues ...interface{})
	Errorw(msg string, keyAndValues ...interface{})
	Fatalw(msg string, keyAndValues ...interface{})
	Sync() error
}

func GetLogger added in v0.20.0

func GetLogger() LoggerInterface

GetLogger gets the package-level base logger

func NewLogger

func NewLogger(cfg LoggerConfig) LoggerInterface

NewLogger function

type LoggingConfig

type LoggingConfig struct {
	Logger        LoggerInterface
	LoggerConfig  LoggerConfig
	Filter        LoggerFilter
	Aggregate     bool
	FlushInterval time.Duration
}

LoggingConfig defines the configuration of the package level logging.

Users importing tracker as a library may choose to construct a tracker flavored logger with NewLogger() or supply their own interface.

Tracker offers aggregation and filtering support on top of any logger implementation complying to it's interface.

func NewDefaultLoggingConfig

func NewDefaultLoggingConfig() LoggingConfig

func (LoggingConfig) SetLevel added in v0.20.0

func (lc LoggingConfig) SetLevel(lvl Level)

SetLevel sets the logging level of the package level logger. It is thread safe.

Jump to

Keyboard shortcuts

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