log

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: GPL-3.0 Imports: 20 Imported by: 4

Documentation

Overview

Package log provides global logging functions to be used throughout the charon app. It supports contextual logging via WithCtx and structured logging and structured errors via z.Field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFields added in v0.3.0

func CopyFields(target context.Context, source context.Context) context.Context

CopyFields returns a copy of the target with which the logging fields of the source context are associated.

func Debug

func Debug(ctx context.Context, msg string, fields ...z.Field)

Debug logs the message and fields (incl fields in the context) at Debug level. Debug should be used for most logging.

func Error

func Error(ctx context.Context, msg string, err error, fields ...z.Field)

Error wraps err with msg and fields and logs it (incl fields in the context) at Error level. Nil err is supported and results in similar behaviour to Info, just at Error level. Error should only be used when a problem is encountered that *does* require action to be taken.

func Filter added in v0.11.0

func Filter(opts ...FilterOption) z.Field

Filter returns a stateful structure logging field that results in logs lines being dropped if internal rate limit is exceeded. Usage:

filter := log.Filter()
for event := range eventPipe() {
  err := process(event)
  if err != nil {
    log.Error(ctx, "This error should only be logged max once an hour", err, filter)
  }
}

func Info

func Info(ctx context.Context, msg string, fields ...z.Field)

Info logs the message and fields (incl fields in the context) at Info level. Info should only be used for high level important events.

func InitConsoleForT added in v0.11.0

func InitConsoleForT(_ *testing.T, ws zapcore.WriteSyncer, opts ...func(*zapcore.EncoderConfig))

InitConsoleForT initialises a console logger for testing purposes.

func InitJSONForT added in v0.11.0

func InitJSONForT(t *testing.T, ws zapcore.WriteSyncer, opts ...func(*zapcore.EncoderConfig))

InitJSONForT initialises a json logger for testing purposes.

func InitLogfmtForT added in v0.11.0

func InitLogfmtForT(t *testing.T, ws zapcore.WriteSyncer, opts ...func(*zapcore.EncoderConfig))

InitLogfmtForT initialises a logfmt logger for testing purposes.

func InitLogger added in v0.2.0

func InitLogger(config Config) error

InitLogger initialises the global logger based on the provided config.

func SetLokiLabels added in v0.13.0

func SetLokiLabels(l map[string]string)

SetLokiLabels sets the global logger loki labels.

func Stop added in v0.12.0

func Stop(ctx context.Context)

Stop stops all log processors.

func Warn

func Warn(ctx context.Context, msg string, err error, fields ...z.Field)

Warn wraps err with msg and fields and logs it (incl fields in the context) at Warn level. Nil err is supported and results in similar behaviour to Info, just at Warn level. Warn should only be used when a problem is encountered that *does not* require any action to be taken.

func WithCtx

func WithCtx(ctx context.Context, fields ...z.Field) context.Context

WithCtx returns a copy of the context with which the logging fields are associated. Usage:

ctx := log.WithCtx(ctx, z.Int("slot", 1234))
...
log.Info(ctx, "Slot processed") // Will contain field: slot=1234

func WithTopic

func WithTopic(ctx context.Context, component string) context.Context

WithTopic is a convenience function that adds the topic contextual logging field to the returned child context.

Types

type Config added in v0.2.0

type Config struct {
	Level         string   // debug, info, warn or error
	Format        string   // console or json
	LokiAddresses []string // URLs for loki logging spout
	LokiService   string   // Value of the service label pushed with loki logs.
}

Config defines the logging configuration.

func DefaultConfig added in v0.2.0

func DefaultConfig() Config

DefaultConfig returns the default logging config.

func (Config) ZapLevel added in v0.2.0

func (c Config) ZapLevel() (zapcore.Level, error)

ZapLevel returns the zapcore level.

type FilterOption added in v0.11.0

type FilterOption func(*filter)

func WithFilterRateLimit added in v0.11.0

func WithFilterRateLimit(limit rate.Limit) FilterOption

WithFilterRateLimit returns a filter option that rate limits logging by a per second limit.

Directories

Path Synopsis
Package loki provides a simple best-effort loki log ingestion client supporting batch sends.
Package loki provides a simple best-effort loki log ingestion client supporting batch sends.

Jump to

Keyboard shortcuts

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