log

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: Apache-2.0 Imports: 9 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 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. TODO(corver): Add indication of when debug should be used.

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. TODO(corver): Add indication of when error should be used.

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. TODO(corver): Add indication of when info should be used.

func InitJSONLogger

func InitJSONLogger() error

InitJSONLogger initialises a JSON logger for production usage.

func InitLoggerForT

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

InitLoggerForT initialises a console logger for testing purposes.

func Warn

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

Warn logs the message and fields (incl fields in the context) at Warn level. TODO(corver): Add indication of when warn should be used.

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

This section is empty.

Jump to

Keyboard shortcuts

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