logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package logger provides a simple logger interface for logging messages. It also provides an out of the box support with the Otel span. The logger is passing metadata to the span, so the logs can be easily correlated with the traces. Furthermore, the logger is recording the span as errored for error logs with a given error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, message string, args ...interface{})

Debug logs a message at the debug level.

Any attributes passed as arguments are added to the log message in the group "metadata", and in the span that is retrieved from the given context.

func Error

func Error(ctx context.Context, message string, err error, args ...interface{})

Error logs a message at the error level.

Any attributes passed as arguments are added to the log message in the group "metadata", and in the span that is retrieved from the given context. Furthermore, if an error is passed as an argument, it is added to the log message in the attribute "error", and also sets the span as errored (if the a span cna be retrieved from the given context).

func Info

func Info(ctx context.Context, message string, args ...interface{})

Info logs a message at the info level.

Any attributes passed as arguments are added to the log message in the group "metadata", and in the span that is retrieved from the given context.

func InitLogger

func InitLogger()

InitLogger initializes the logger with the given configuration.

The logger is then selected as the default logger for the application.

func Warn

func Warn(ctx context.Context, message string, args ...interface{})

Warn logs a message at the warn level.

Any attributes passed as arguments are added to the log message in the group "metadata", and in the span that is retrieved from the given context.

Types

type Attribute

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

Attribute is a wrapper around the log attributes

func NewAttribute

func NewAttribute() *Attribute

NewAttribute creates a new attribute

func (*Attribute) Get

func (a *Attribute) Get(ctx context.Context) []slog.Attr

Get returns the log attributes

func (*Attribute) WithError

func (a *Attribute) WithError(err error) *Attribute

WithError sets the error in the attribute

func (*Attribute) WithMetadata

func (a *Attribute) WithMetadata(args ...interface{}) *Attribute

WithMetadata sets the metadata in the attribute

func (*Attribute) WithOutInjectingAttrsToSpan

func (a *Attribute) WithOutInjectingAttrsToSpan() *Attribute

WithOutInjectingAttrsToSpan disables injecting attributes to the span

Jump to

Keyboard shortcuts

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