logging

package
v0.0.0-...-85cd7ee Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JsonHandler    = LoggingHandle("json")
	TextHandler    = LoggingHandle("text")
	SentryHandler  = LoggingHandle("sentry")
	RollbarHandler = LoggingHandle("rollbar")
	DatadogHandler = LoggingHandle("datadog")
)

Variables

View Source
var (
	IgnoreTracing = slog.Attr{
		Key:   "Ignore",
		Value: slog.BoolValue(true),
	}
)
View Source
var StdLogger = log.New(&writer{}, "goff", log.LstdFlags)

Functions

func Debug

func Debug(msg string, args ...any)

func DebugContext

func DebugContext(ctx context.Context, msg string, args ...any)

func Error

func Error(msg string, args ...any)

func ErrorContext

func ErrorContext(ctx context.Context, msg string, args ...any)

func Info

func Info(msg string, args ...any)

func InfoContext

func InfoContext(ctx context.Context, msg string, args ...any)

func LoggingHandlersToInf

func LoggingHandlersToInf() []interface{}

func NewAsyncHandler

func NewAsyncHandler(h slog.Handler) slog.Handler

func NewJSONHandler

func NewJSONHandler(opts ...Option) slog.Handler

func NewTextHandler

func NewTextHandler(opts ...Option) slog.Handler

func Warn

func Warn(msg string, args ...any)

func WarnContext

func WarnContext(ctx context.Context, msg string, args ...any)

func WithStack

func WithStack(err error) slog.Attr

Types

type AsyncHandler

type AsyncHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func (*AsyncHandler) Close

func (h *AsyncHandler) Close() error

func (*AsyncHandler) Handle

func (h *AsyncHandler) Handle(ctx context.Context, r slog.Record) error

func (*AsyncHandler) WithAttrs

func (h *AsyncHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*AsyncHandler) WithGroup

func (h *AsyncHandler) WithGroup(name string) slog.Handler

type ErrorTracking

type ErrorTracking struct {
	slog.Handler
	// contains filtered or unexported fields
}

func (*ErrorTracking) Close

func (h *ErrorTracking) Close() error

func (*ErrorTracking) Handle

func (h *ErrorTracking) Handle(ctx context.Context, record slog.Record) error

func (*ErrorTracking) WithAttrs

func (h *ErrorTracking) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ErrorTracking) WithGroup

func (h *ErrorTracking) WithGroup(name string) slog.Handler

type Handle

type Handle interface {
	slog.Handler
	io.Closer
}

func NewDatadogHandler

func NewDatadogHandler(service Service, handler slog.Handler) Handle

func NewErrorTracking

func NewErrorTracking(handler slog.Handler) Handle

func NewHandler

func NewHandler(handlers ...slog.Handler) Handle

func NewRollbarHandler

func NewRollbarHandler(conf *RollbarConfig) Handle

func NewSentryHandler

func NewSentryHandler(conf *SentryConfig, environment string) Handle

type LoggingHandle

type LoggingHandle string

func (LoggingHandle) String

func (h LoggingHandle) String() string

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithHandler

func WithHandler(handler slog.Handler) Option

func WithLevel

func WithLevel(level slog.Leveler) Option

func WithReplaceAttr

func WithReplaceAttr(attrFn ReplaceAttr) Option

func WithWriter

func WithWriter(writer io.Writer) Option

type ReplaceAttr

type ReplaceAttr func(groups []string, a slog.Attr) slog.Attr

type RollbarConfig

type RollbarConfig struct {
	Level string `yaml:"level" default:"warn"`
	Token string `yaml:"token"`
	Env   string `yaml:"env"`

	Client *http.Client
	// contains filtered or unexported fields
}

func (*RollbarConfig) Close

func (c *RollbarConfig) Close()

func (*RollbarConfig) Init

func (c *RollbarConfig) Init(env, version, serverRoot string)

func (RollbarConfig) Validate

func (c RollbarConfig) Validate() error

type SentryConfig

type SentryConfig struct {
	Level          string           `yaml:"level" default:"warn"`
	DSN            string           `yaml:"dsn"`
	SampleRate     float64          `yaml:"sampleRate" default:"1.0"`
	IgnoreErrors   []string         `yaml:"ignoreErrors"`
	SendDefaultPII bool             `yaml:"sendDefaultPII"`
	Env            string           `yaml:"env"`
	Transport      sentry.Transport `yaml:"-"`
}

func (*SentryConfig) SentryOptions

func (c *SentryConfig) SentryOptions(environment string) sentry.ClientOptions

func (SentryConfig) Validate

func (c SentryConfig) Validate() error

type Service

type Service interface {
	ServiceName() string
	Environment() string
	Version() string
}

Jump to

Keyboard shortcuts

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