oopslogrus

package module
v0.0.0-...-5d0edf2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: MIT Imports: 3 Imported by: 5

README

Logrus formatter for Oops

import oopslogrus "github.com/samber/oops/loggers/logrus"

func init() {
    logrus.SetFormatter(
        oopslogrus.NewOopsFormatter(
	    &logrus.JSONFormatter{},
        )
    )
}

func main() {
    err := oops.
        With("driver", "postgresql").
        With("query", query).
        With("query.duration", queryDuration).
        Errorf("could not fetch user")

    if err != nil {
    	logrus.WithError(err).Error(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOopsFormatter

func NewOopsFormatter(secondaryFormatter logrus.Formatter) *oopsFormatter

NewOopsFormatter creates a new logrus formatter that automatically detects and formats oops.OopsError instances in log entries.

This formatter wraps an existing logrus formatter and enhances it with oops error handling capabilities. When an oops.OopsError is detected in a log entry's "error" field, the formatter automatically extracts all error context, metadata, and stack traces and adds them to the log entry data.

If no secondary formatter is provided, the standard logrus formatter is used as the underlying formatter.

Example usage:

logger := logrus.New()
logger.SetFormatter(oopslogrus.NewOopsFormatter(nil))
logger.WithError(err).Error("operation failed")

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL