RapidGo
No results found

Logging

Structured logging with slog, multiple output formats, and file support.

RapidGo uses Go's standard log/slog package for structured logging with configurable levels, formats, and outputs.

Configuration

LOG_LEVEL=debug    # debug, info, warn, error
LOG_FORMAT=json    # json, text
LOG_OUTPUT=stdout  # stdout, file

Setup

The logger is configured automatically by the LoggerProvider:

import "github.com/RAiWorks/RapidGo/v2/core/logger"

// Called by LoggerProvider — sets slog.SetDefault()
log := logger.Setup()

After setup, use slog anywhere in your application:

import "log/slog"

slog.Info("user registered", "user_id", user.ID, "email", user.Email)
slog.Error("payment failed", "order_id", order.ID, "error", err)
slog.Debug("cache hit", "key", cacheKey)
slog.Warn("rate limit approaching", "ip", clientIP, "count", count)

Log Levels

Level Description
debug Verbose development information
info General operational events
warn Potential issues that aren't errors
error Errors that need attention

Output Formats

JSON (default)

{"time":"2026-01-15T10:30:00Z","level":"INFO","msg":"user registered","user_id":42,"email":"user@example.com"}

Text

time=2026-01-15T10:30:00Z level=INFO msg="user registered" user_id=42 email=user@example.com

File Output

When LOG_OUTPUT=file, logs are written to storage/logs/app.log. The directory is created automatically. Call logger.Close() on shutdown to flush and close the file handle.