Skip to main content

Logger/slog - Plugin operators

This page lists all operators available in the observability/slog sub-package of ro.

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!

Installโ€‹

First, import the sub-package in your project:

go get -u github.com/samber/ro/plugins/observability/slog
  • 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
    // Completed
    Prototype:
    func Log[T any](logger slog.Logger, level slog.Level)