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 ¶
- func CopyFields(target context.Context, source context.Context) context.Context
- func Debug(ctx context.Context, msg string, fields ...z.Field)
- func Error(ctx context.Context, msg string, err error, fields ...z.Field)
- func Info(ctx context.Context, msg string, fields ...z.Field)
- func InitLogger(config Config) error
- func InitLoggerForT(_ *testing.T, ws zapcore.WriteSyncer, opts ...func(*zapcore.EncoderConfig))
- func Warn(ctx context.Context, msg string, err error, fields ...z.Field)
- func WithCtx(ctx context.Context, fields ...z.Field) context.Context
- func WithTopic(ctx context.Context, component string) context.Context
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFields ¶ added in v0.3.0
CopyFields returns a copy of the target with which the logging fields of the source context are associated.
func Debug ¶
Debug logs the message and fields (incl fields in the context) at Debug level. Debug should be used for most logging.
func Error ¶
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 ¶
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
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 ¶
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.
Types ¶
type Config ¶ added in v0.2.0
Config defines the logging configuration.
func DefaultConfig ¶ added in v0.2.0
func DefaultConfig() Config
DefaultConfig returns the default logging config.