logger
import "github.com/prescriptoo/prescriptoo-api/pkg/logger"Package logger provides structured logging interfaces using slog.
Index
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Default() *slog.Logger
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func FromContext(ctx context.Context) *slog.Logger
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func NewTraceID() string
- func SetDefault(l *slog.Logger)
- func TraceAttributes(ctx context.Context, includeStack bool) []any
- func TraceID(ctx context.Context) string
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- func With(ctx context.Context, args ...any) context.Context
- func WithTrace(ctx context.Context, traceID string) context.Context
- type Span
- type TraceStep
func Debug
func Debug(msg string, args ...any)Debug logs a debug message with optional key-value attributes.
func DebugContext
func DebugContext(ctx context.Context, msg string, args ...any)DebugContext writes a debug record using request-scoped attributes.
func Default
func Default() *slog.LoggerDefault returns the default slog.Logger.
func Error
func Error(msg string, args ...any)Error logs an error message with optional key-value attributes.
func ErrorContext
func ErrorContext(ctx context.Context, msg string, args ...any)ErrorContext writes an error record using request-scoped attributes.
func FromContext
func FromContext(ctx context.Context) *slog.LoggerFromContext returns the request-scoped logger, or the process logger when no request logger has been attached.
func Info
func Info(msg string, args ...any)Info logs an informational message with optional key-value attributes.
func InfoContext
func InfoContext(ctx context.Context, msg string, args ...any)InfoContext writes an informational record using request-scoped attributes.
func NewTraceID
func NewTraceID() stringNewTraceID returns a random identifier suitable for correlating request logs.
func SetDefault
func SetDefault(l *slog.Logger)SetDefault sets the default slog.Logger.
func TraceAttributes
func TraceAttributes(ctx context.Context, includeStack bool) []anyTraceAttributes 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
func TraceID(ctx context.Context) stringTraceID returns the trace identifier attached to ctx.
func Warn
func Warn(msg string, args ...any)Warn logs a warning message with optional key-value attributes.
func WarnContext
func WarnContext(ctx context.Context, msg string, args ...any)WarnContext writes a warning record using request-scoped attributes.
func With
func With(ctx context.Context, args ...any) context.ContextWith adds structured attributes to the logger stored in ctx.
func WithTrace
func WithTrace(ctx context.Context, traceID string) context.ContextWithTrace 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.
type Span struct {
// contains filtered or unexported fields
}func StartSpan
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
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.
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