Logger/Logrus - Plugin operators
This page lists all operators available in the observability/logrus 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/logrus
Logโ
Logs with logrus.
import ("fmt""os""github.com/samber/ro"rologrus "github.com/samber/ro/plugins/observability/logrus""github.com/sirupsen/logrus")logger := logrus.New()logger.SetOutput(os.Stdout)logger.SetLevel(logrus.InfoLevel)logger.SetFormatter(&logrus.TextFormatter{DisableColors: true,DisableTimestamp: true,})values, err := ro.Collect(ro.Pipe1(ro.Just("message 1", "message 2"),rologrus.Log[string](logger, logrus.InfoLevel),),)for _, v := range values {fmt.Printf("Next: %s\n", v)}if err != nil {fmt.Printf("Error: %v\n", err)} else {fmt.Println("Completed")}// level=info msg="ro.Next: message 1"// level=info msg="ro.Next: message 2"// level=info msg=ro.Complete// Next: message 1// Next: message 2// CompletedVariant:Similar:Prototype:func Log[T any](logger *logrus.Logger, level logrus.Level)LogWithNotificationโ
Logs with logrus with structured fields and notifications.
import ("fmt""os""github.com/samber/ro"rologrus "github.com/samber/ro/plugins/observability/logrus""github.com/sirupsen/logrus")logger := logrus.New()logger.SetOutput(os.Stdout)logger.SetLevel(logrus.InfoLevel)logger.SetFormatter(&logrus.TextFormatter{DisableColors: true,DisableTimestamp: true,})values, err := ro.Collect(ro.Pipe1(ro.Just("user login", "data processing", "task completed"),rologrus.LogWithNotification[string](logger, logrus.InfoLevel),),)for _, v := range values {fmt.Printf("Next: %s\n", v)}if err != nil {fmt.Printf("Error: %v\n", err)} else {fmt.Println("Completed")}// level=info msg=ro.Next value="user login"// level=info msg=ro.Next value="data processing"// level=info msg=ro.Next value="task completed"// level=info msg=ro.Complete// Next: user login// Next: data processing// Next: task completed// CompletedVariant:Similar:Prototype:func LogWithNotification[T any](logger *logrus.Logger, level logrus.Level)FatalOnErrorโ
Fatal logs errors using logrus and terminates the application.
import ("fmt""os""github.com/samber/ro"rologrus "github.com/samber/ro/plugins/observability/logrus""github.com/sirupsen/logrus")logger := logrus.New()logger.SetOutput(os.Stdout)logger.SetFormatter(&logrus.TextFormatter{DisableColors: true,DisableTimestamp: true,})// Override exit so the Playground process doesn't terminatelogger.ExitFunc = func(code int) {fmt.Printf("[os.Exit(%d) would be called here]\n", code)}_, err := ro.Collect(ro.Pipe1(ro.Throw[string](fmt.Errorf("something went wrong")),rologrus.FatalOnError[string](logger),),)if err != nil {fmt.Printf("Stream error: %v\n", err)}// level=fatal msg=ro.Error error="something went wrong"// [os.Exit(1) would be called here]// Stream error: something went wrongSimilar:Prototype:func FatalOnError[T any](logger *logrus.Logger)