Backend fixes: - migration 003: add 'menu' value to recipe_source enum (was causing SQLSTATE 22P02) - migration 004: rename recipe_products→recipe_ingredients, product_id→ingredient_id (was causing SQLSTATE 42P01) - dish/repository.go: fix INSERT INTO tags using $1/$1 for two columns → $1/$2 (was causing SQLSTATE 42P08) - home/handler.go: replace non-existent saved_recipes table with correct joins (recipes→dishes→dish_translations, user_saved_recipes) so today's plan and recommendations load correctly - reqlog: new slog.Handler wrapper that adds request_id and stack trace to ERROR-level logs - all handlers: slog.Error→slog.ErrorContext so error logs include request context; writeError includes request_id in response body Client: - home_screen.dart: extend home screen to future dates, show planned meals as ghost entries - l10n: add new localisation keys for home screen date navigation and planned meal UI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package reqlog
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"runtime/debug"
|
|
|
|
"github.com/food-ai/backend/internal/infra/middleware"
|
|
)
|
|
|
|
// Handler is a slog.Handler wrapper that enriches ERROR-level records with
|
|
// the request_id from context and a goroutine stack trace.
|
|
type Handler struct {
|
|
inner slog.Handler
|
|
}
|
|
|
|
// New wraps inner with request-aware enrichment.
|
|
func New(inner slog.Handler) *Handler {
|
|
return &Handler{inner: inner}
|
|
}
|
|
|
|
func (handler *Handler) Handle(ctx context.Context, record slog.Record) error {
|
|
if record.Level >= slog.LevelError {
|
|
if requestID := middleware.RequestIDFromCtx(ctx); requestID != "" {
|
|
record.AddAttrs(slog.String("request_id", requestID))
|
|
}
|
|
record.AddAttrs(slog.String("stack", string(debug.Stack())))
|
|
}
|
|
return handler.inner.Handle(ctx, record)
|
|
}
|
|
|
|
func (handler *Handler) Enabled(ctx context.Context, level slog.Level) bool {
|
|
return handler.inner.Enabled(ctx, level)
|
|
}
|
|
|
|
func (handler *Handler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
|
return &Handler{inner: handler.inner.WithAttrs(attrs)}
|
|
}
|
|
|
|
func (handler *Handler) WithGroup(name string) slog.Handler {
|
|
return &Handler{inner: handler.inner.WithGroup(name)}
|
|
}
|