logging

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogError

func LogError(err error, logger *slog.Logger, args ...any)

LogError logs an error with context.

func LogRequest

func LogRequest(r *http.Request, statusCode int, duration time.Duration, logger *slog.Logger)

LogRequest logs an HTTP request with standard fields.

func LogWithContext

func LogWithContext(r *http.Request, logger *slog.Logger) *slog.Logger

LogWithContext creates a logger enriched from an HTTP request context.

func RequestMiddleware

func RequestMiddleware(logger *slog.Logger) func(http.Handler) http.Handler

RequestMiddleware returns an HTTP middleware that enriches the context with request metadata.

func Setup

func Setup(cfg Config) *slog.Logger

Setup configures and returns the application logger.

func With

func With(logger *slog.Logger, args ...any) *slog.Logger

With returns a logger enriched with the given key-value pairs.

func WithContext

func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger

WithContext enriches the logger with values extracted from context.

Types

type Config

type Config struct {
	Level    string
	Channel  string   // e.g. "single", "daily", "stack"
	Path     string   // path to log directory
	Channels []string // used if Channel == "stack"
	MaxAge   int      // max days to keep log files (0 = unlimited)
	MaxSize  int64    // max file size in bytes (0 = unlimited)
}

Config represents logging configuration.

type ContextKey

type ContextKey string

ContextKey is a type for context keys to avoid collisions.

const (
	RequestIDKey ContextKey = "request_id"
	UserIDKey    ContextKey = "user_id"
	TenantIDKey  ContextKey = "tenant_id"
	ChannelKey   ContextKey = "channel"
	ExtraKey     ContextKey = "extra"
)

type ServiceProvider

type ServiceProvider struct {
	foundation.BaseServiceProvider
}

ServiceProvider registers the logging system.

func (*ServiceProvider) Register

func (p *ServiceProvider) Register(app *foundation.Application)

Register registers the logger into the container.

Jump to

Keyboard shortcuts

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