Skip to content

logger ​

go
import "github.com/prescriptoo/prescriptoo-api/pkg/logger"

Package logger provides structured logging interfaces using slog.

Index ​

func Debug ​

go
func Debug(msg string, args ...any)

Debug logs a debug message with optional key-value attributes.

func DebugContext ​

go
func DebugContext(ctx context.Context, msg string, args ...any)

DebugContext writes a debug record using request-scoped attributes.

func Default ​

go
func Default() *slog.Logger

Default returns the default slog.Logger.

func Error ​

go
func Error(msg string, args ...any)

Error logs an error message with optional key-value attributes.

func ErrorContext ​

go
func ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext writes an error record using request-scoped attributes.

func FromContext ​

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

FromContext returns the request-scoped logger, or the process logger when no request logger has been attached.

func Info ​

go
func Info(msg string, args ...any)

Info logs an informational message with optional key-value attributes.

func InfoContext ​

go
func InfoContext(ctx context.Context, msg string, args ...any)

InfoContext writes an informational record using request-scoped attributes.

func NewTraceID ​

go
func NewTraceID() string

NewTraceID returns a random identifier suitable for correlating request logs.

func SetDefault ​

go
func SetDefault(l *slog.Logger)

SetDefault sets the default slog.Logger.

func TraceAttributes ​

go
func TraceAttributes(ctx context.Context, includeStack bool) []any

TraceAttributes returns a stable snapshot for a final request error log. Stack data is optional because it should normally be restricted to 5xx logs.

func TraceID ​

go
func TraceID(ctx context.Context) string

TraceID returns the trace identifier attached to ctx.

func Warn ​

go
func Warn(msg string, args ...any)

Warn logs a warning message with optional key-value attributes.

func WarnContext ​

go
func WarnContext(ctx context.Context, msg string, args ...any)

WarnContext writes a warning record using request-scoped attributes.

func With ​

go
func With(ctx context.Context, args ...any) context.Context

With adds structured attributes to the logger stored in ctx.

func WithTrace ​

go
func WithTrace(ctx context.Context, traceID string) context.Context

WithTrace starts a trace and attaches its ID to all logs written with ctx.

type Span ​

Span records a single request operation. End must be called exactly once.

go
type Span struct {
    // contains filtered or unexported fields
}

func StartSpan ​

go
func StartSpan(ctx context.Context, operation string) (context.Context, *Span)

StartSpan records entry into an operation. The returned context should be passed to nested operations so all stages share the same trace.

func (*Span) End ​

go
func (s *Span) End(err error)

End completes a span and records the first failing operation and its stack.

type TraceStep ​

TraceStep describes one function or dependency boundary crossed by a request.

go
type TraceStep struct {
    Operation string        `json:"operation"`
    Duration  time.Duration `json:"duration"`
    Failed    bool          `json:"failed,omitempty"`
    Error     string        `json:"error,omitempty"`
    // contains filtered or unexported fields
}

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.