logging

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize()

Initialize initializes the logging.

func InjectCorrelationIDInContext

func InjectCorrelationIDInContext(ctx context.Context, id string) context.Context

InjectCorrelationIDInContext injects the correlation ID into the provided context, that allow to log with this ID making easy to identify all logs related to the same execution.

Types

type Logging

type Logging struct {
	// contains filtered or unexported fields
}

Logging is a struct that contains the parameters for the logging.

func Debug

func Debug(ctx context.Context) *Logging

Debug returns a new Logging instance configured for DEBUG level log.

func Error

func Error(ctx context.Context) *Logging

Error returns a new Logging instance configured for ERROR level log.

func Fatal

func Fatal(ctx context.Context) *Logging

Fatal returns a new Logging instance configured for ERROR level log. After the log is printed, a panic is thrown.

func Info

func Info(ctx context.Context) *Logging

Info returns a new Logging instance configured for INFO level log.

func Warn

func Warn(ctx context.Context) *Logging

Warn returns a new Logging instance configured for WARN level log.

func (*Logging) AddParam

func (l *Logging) AddParam(key string, val any) *Logging

AddParam adds a key-value pair to the logging parameters. Example:

logging.Info(ctx).AddParam("userID", 123).Msg("User logged in")

func (*Logging) Err

func (l *Logging) Err(err error) *Logging

Err sets the error field in the Logging instance. When an error is added, the log will include a specific field for the error. error. Example:

err := errors.New("database connection failed")

logging.Error(ctx).Err(err).Msg("Database error")

func (*Logging) Msg

func (l *Logging) Msg(msg string)

Msg logs a message with the appropriate log level and parameters. Example:

logging.Info(ctx).AddParam("userID", 123).Msg("User logged in")

func (*Logging) Msgf

func (l *Logging) Msgf(msg string, args ...any)

Msgf logs a formatted message with the appropriate log level. Example:

logging.Info(ctx).Msgf("User %s logged in at %s", "John", time.Now().Format(time.RFC3339))

Jump to

Keyboard shortcuts

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