Help improve this documentation
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
Logger/slog operatorsโ
This page lists all operators available in the observability/slog sub-package of ro.
Installโ
First, import the sub-package in your project:
go get -u github.com/samber/ro/plugins/observability/slog
Logโ
Logs with structured logging.
import (
"log/slog"
"os"
"github.com/samber/ro"
roslog "github.com/samber/ro/plugins/observability/slog"
)
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
obs := ro.Pipe[string, string](
ro.Just("operation 1", "operation 2"),
roslog.Log[string](logger, slog.LevelInfo),
)
sub := obs.Subscribe(ro.PrintObserver[string]())
defer sub.Unsubscribe()
// Logs: time=... level=INFO msg="operation 1"
// Logs: time=... level=INFO msg="operation 2"
// Next: operation 1
// Next: operation 2
// CompletedSimilar:Prototype:func Log[T any](logger slog.Logger, level slog.Level)