Documentation
¶
Index ¶
- func LogError(err error, logger *slog.Logger, args ...any)
- func LogRequest(r *http.Request, statusCode int, duration time.Duration, logger *slog.Logger)
- func LogWithContext(r *http.Request, logger *slog.Logger) *slog.Logger
- func RequestMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func Setup(cfg Config) *slog.Logger
- func With(logger *slog.Logger, args ...any) *slog.Logger
- func WithContext(ctx context.Context, logger *slog.Logger) *slog.Logger
- type Config
- type ContextKey
- type ServiceProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogRequest ¶
LogRequest logs an HTTP request with standard fields.
func LogWithContext ¶
LogWithContext creates a logger enriched from an HTTP request context.
func RequestMiddleware ¶
RequestMiddleware returns an HTTP middleware that enriches the context with request metadata.
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.
Click to show internal directories.
Click to hide internal directories.