log

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: GPL-3.0 Imports: 16 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 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 InitLogger added in v0.2.0

func InitLogger(config Config) error

InitLogger initialises the global logger based on the provided config.

func InitLoggerForT

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

InitLoggerForT initialises a console logger for testing purposes.

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
}

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.

Jump to

Keyboard shortcuts

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