log

package
v0.0.0-...-b7aacc1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string)

Debug logs the given msg at log level DEBUG

func Debugf

func Debugf(format string, a ...any)

Debugf logs the given formatted msg at log level DEBUG

func Error

func Error(msg string)

Error logs the given msg at log level ERROR

func Errorf

func Errorf(format string, a ...any)

Errorf logs the given formatted msg at log level ERROR

func GetKeyVals

func GetKeyVals(ctx context.Context) []any

GetKeyVals returns the logging keyvals from the given context if there are any

func Info

func Info(msg string)

Info logs the given msg at log level INFO

func Infof

func Infof(format string, a ...any)

Infof logs the given formatted msg at log level INFO

func Reset

func Reset()

Reset returns the logger state to the default nop logger and enables Setup to be called again.

func Setup

func Setup(logger tmlog.Logger)

Setup sets the logger that the application should use. The default is a nop logger, i.e. all logs are discarded. Panics if called more than once without calling Reset first.

Types

type Context

type Context struct {
	context.Context
}

Context is a wrapper around context.Context that allows to append keyvals to the context.

func Append

func Append(ctx context.Context, key, val any) Context

Append adds the given keyval pair to the given context. If the context already stores keyvals, the new ones get appended. This should be used to track the logging context across the application.

func AppendKeyVals

func AppendKeyVals(ctx context.Context, keyvals ...any) Context

AppendKeyVals adds the given keyvals to the given context. If the context already stores keyvals, the new ones get appended. Use Append instead if you only want to add a single keyval pair. This should be used to track the logging context across the application.

func (Context) Append

func (c Context) Append(key, val any) Context

Append adds the given keyval pair to the logging context. If the context already stores keyvals, the new ones get appended.

type Logger

type Logger interface {
	Debug(msg string)
	Debugf(format string, a ...any)
	Info(msg string)
	Infof(format string, a ...any)
	Error(msg string)
	Errorf(format string, a ...any)
}

Logger is a simple interface to log at three log levels with additional formatting methods for convenience

func FromCtx

func FromCtx(ctx context.Context) Logger

FromCtx reads logging keyvals from the given context if there are any and adds them to any logs the returned Logger puts out

func With

func With(key, val any) Logger

With returns a logger that adds the given keyval pair to any logs it puts out. This should be used for immediate log enrichment, for tracking of a logging context across the application use Append

func WithKeyVals

func WithKeyVals(keyvals ...any) Logger

WithKeyVals returns a logger that adds the given keyvals to any logs it puts out. This should be used for immediate log enrichment, for tracking of a logging context across the application use AppendKeyVals

Jump to

Keyboard shortcuts

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