logger

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields Fields)

Debug logs at level Debug with fields.

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs at level Debug (no trace/correlation).

func DebugfContext added in v0.1.11

func DebugfContext(ctx context.Context, format string, args ...interface{})

DebugfContext logs at level Debug with trace_id/correlation_id from ctx.

func Error

func Error(msg string, fields Fields)

Error logs at level Error with fields.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs at level Error (no trace/correlation).

func ErrorfContext added in v0.1.11

func ErrorfContext(ctx context.Context, format string, args ...interface{})

ErrorfContext logs at level Error with trace_id/correlation_id from ctx.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs at level Error and exits with code 1.

func GetCorrelationID added in v0.1.11

func GetCorrelationID(ctx context.Context) string

GetCorrelationID returns the correlation ID from ctx if set, otherwise empty string.

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the underlying slog.Logger instance

func GetTraceID added in v0.1.11

func GetTraceID(ctx context.Context) string

GetTraceID returns the trace ID from ctx if set, otherwise empty string.

func GetWriter added in v0.2.0

func GetWriter() io.Writer

GetWriter returns the io.Writer used for logging (file + stderr). Use this when an io.Writer is needed, e.g. for GORM database logger.

func Info

func Info(msg string, fields Fields)

Info logs at level Info with fields.

func Infof

func Infof(format string, args ...interface{})

Infof logs at level Info (no trace/correlation).

func InfofContext added in v0.1.11

func InfofContext(ctx context.Context, format string, args ...interface{})

InfofContext logs at level Info with trace_id/correlation_id from ctx.

func SetLogLevel

func SetLogLevel(level slog.Level)

SetLogLevel sets the log level for the logger

func Warn

func Warn(msg string, fields Fields)

Warn logs at level Warn with fields.

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs at level Warn (no trace/correlation).

func WarnfContext added in v0.1.11

func WarnfContext(ctx context.Context, format string, args ...interface{})

WarnfContext logs at level Warn with trace_id/correlation_id from ctx.

func WithCorrelationID added in v0.1.11

func WithCorrelationID(ctx context.Context, correlationID string) context.Context

WithCorrelationID returns a copy of ctx with the given correlation ID.

func WithTraceID added in v0.1.11

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID returns a copy of ctx with the given trace ID.

Types

type Ctx added in v0.1.12

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

Ctx is a logger bound to a context. Use WithContext to create it; then Infof, Debugf, etc. automatically include trace_id and correlation_id from that context in the JSON output.

func WithContext added in v0.1.12

func WithContext(ctx context.Context) *Ctx

WithContext returns a context-bound logger. Calls to Infof, Debugf, Warnf, Errorf (and Debug, Info, Warn, Error) on the returned value will automatically include trace_id and correlation_id from ctx in the log JSON. Use this in request handlers after trace middleware has set the context, e.g.:

log := logger.WithContext(c.Request.Context())
log.Infof("user %s logged in", userID)

func (*Ctx) Debug added in v0.1.12

func (c *Ctx) Debug(msg string, fields Fields)

Debug logs at level Debug with fields; includes trace_id/correlation_id from the bound context.

func (*Ctx) Debugf added in v0.1.12

func (c *Ctx) Debugf(format string, args ...interface{})

Debugf logs at level Debug with trace_id/correlation_id from the bound context.

func (*Ctx) Error added in v0.1.12

func (c *Ctx) Error(msg string, fields Fields)

Error logs at level Error with fields; includes trace_id/correlation_id from the bound context.

func (*Ctx) Errorf added in v0.1.12

func (c *Ctx) Errorf(format string, args ...interface{})

Errorf logs at level Error with trace_id/correlation_id from the bound context.

func (*Ctx) Fatalf added in v0.1.12

func (c *Ctx) Fatalf(format string, args ...interface{})

Fatalf logs at level Error and exits with code 1; includes trace_id/correlation_id from the bound context.

func (*Ctx) Info added in v0.1.12

func (c *Ctx) Info(msg string, fields Fields)

Info logs at level Info with fields; includes trace_id/correlation_id from the bound context.

func (*Ctx) Infof added in v0.1.12

func (c *Ctx) Infof(format string, args ...interface{})

Infof logs at level Info with trace_id/correlation_id from the bound context.

func (*Ctx) Warn added in v0.1.12

func (c *Ctx) Warn(msg string, fields Fields)

Warn logs at level Warn with fields; includes trace_id/correlation_id from the bound context.

func (*Ctx) Warnf added in v0.1.12

func (c *Ctx) Warnf(format string, args ...interface{})

Warnf logs at level Warn with trace_id/correlation_id from the bound context.

type Fields

type Fields map[string]interface{}

Fields is a map of key-value pairs for structured logging

Jump to

Keyboard shortcuts

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