logger

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: BSD-3-Clause-Clear Imports: 13 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigPrefix = ""

Functions

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext retrieves a logger from the context. If there is none, it returns the default logger

func NewContext

func NewContext(ctx context.Context, l *slog.Logger) context.Context

NewContext adds the logger to the context. Use this to for example make a request specific logger available to other functions through the context

func NewStdLog

func NewStdLog(key string, debug bool, log *slog.Logger) *stdLoggerish

func Setup

func Setup() *slog.Logger

Setup returns an slog.Logger configured for text formatting to stderr. OpenTelemetry trace_id and span_id's are logged as attributes when available. When the application is running under systemd timestamps are omitted. On first call the slog default logger is set to this logger as well.

If SetupMultiLogger has been called Setup() will return the "multi logger"

func SetupMultiLogger added in v0.3.0

func SetupMultiLogger() *slog.Logger

SetupMultiLogger will setup and make default a logger that logs as described in Setup() as well as an OLTP logger. The "multi logger" is made the default the first time this function is called

func SetupOLTP added in v0.3.0

func SetupOLTP() *slog.Logger

SetupOLTP configures and returns a logger sending logs via OpenTelemetry (configured via the tracing package).

This was made to work with Loki + Grafana that makes it hard to view the log attributes in the UI, so the log message is formatted similarly to the text logger. The attributes are duplicated as OLTP attributes in the log messages. https://github.com/grafana/loki/issues/14788

Types

type Error

type Error struct {
	Msg  string
	Data []any
}

func NewError

func NewError(msg string, data ...any) *Error

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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