logging

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package logging provides support for multiple upstream logger libraries. It contains convenience methods and types to instrument logs in a transparent way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenTelemetryHandler

type OpenTelemetryHandler struct {
	Logger log.Logger
	Group  string
	Attrs  []slog.Attr
}

OpenTelemetryHandler is a slog.Handler that emits OpenTelemetry log records.

See https://pkg.go.dev/log/slog#Handler

func (*OpenTelemetryHandler) Enabled

func (handler *OpenTelemetryHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if the OpenTelemetry logger emits records for this context and level.

func (*OpenTelemetryHandler) Handle

func (handler *OpenTelemetryHandler) Handle(ctx context.Context, rec slog.Record) error

Handle emits an OpenTelemetry log entry with the data from the record.

func (*OpenTelemetryHandler) WithAttrs

func (handler *OpenTelemetryHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new instance with additional key/value attributes.

func (*OpenTelemetryHandler) WithGroup

func (handler *OpenTelemetryHandler) WithGroup(name string) slog.Handler

WithGroup returns a new instance with the specified group name appended.

type OpenTelemetryLogSink

type OpenTelemetryLogSink struct {
	//nolint:containedctx // logr does not receive a context value on its methods
	Context    context.Context
	Logger     log.Logger
	Name       string
	Attributes []log.KeyValue
}

OpenTelemetryLogSink is a logr.LogSink that emits OpenTelemetry log records.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (*OpenTelemetryLogSink) Enabled

func (*OpenTelemetryLogSink) Enabled(_ int) bool

Enabled always returns true.

func (*OpenTelemetryLogSink) Error

func (sink *OpenTelemetryLogSink) Error(err error, msg string, keysAndValues ...any)

Error emits an OpenTelemetry log entry with an error severity.

func (*OpenTelemetryLogSink) Info

func (sink *OpenTelemetryLogSink) Info(_ int, msg string, keysAndValues ...any)

Info emits an OpenTelemetry log entry with an info severity.

func (*OpenTelemetryLogSink) Init

Init does nothing. It exists to satisfy the logr.LogSink interface.

func (*OpenTelemetryLogSink) WithName

func (sink *OpenTelemetryLogSink) WithName(name string) logr.LogSink

WithName returns a new OpenTelemetrySink with the specified name appended.

func (*OpenTelemetryLogSink) WithValues

func (sink *OpenTelemetryLogSink) WithValues(keysAndValues ...any) logr.LogSink

WithValues returns a new OpenTelemetrySink with additional key/value pairs.

type StandardLogSink

type StandardLogSink struct {
	// contains filtered or unexported fields
}

StandardLogSink is an adatpter to use the standard log as a logr sink.

It creates two loggers internally, one for the standard output and one for the standard error. It writes Info messages on the former and error ones on the latter.

func NewStandardLogSink

func NewStandardLogSink() *StandardLogSink

NewStandardLogSink initializes a StandardLogSink for use.

It creates two standard log.Logger instances: one for information messages, sent to the standard output descriptor; and another for error messages, sent to the standard error descriptor.

func (*StandardLogSink) Enabled

func (*StandardLogSink) Enabled(_ int) bool

Enabled always returns true.

func (*StandardLogSink) Error

func (sink *StandardLogSink) Error(err error, msg string, keysAndValues ...any)

Error prints a log message on the standard error descriptor.

func (*StandardLogSink) Info

func (sink *StandardLogSink) Info(_ int, msg string, keysAndValues ...any)

Info prints a log message on the standard output descriptor.

func (*StandardLogSink) Init

func (*StandardLogSink) Init(_ logr.RuntimeInfo)

Init does nothing. It exists to satisfy the logr.LogSink interface.

func (*StandardLogSink) WithName

func (sink *StandardLogSink) WithName(name string) logr.LogSink

WithName returns a new StandardLogSink with the specified name appended.

func (*StandardLogSink) WithValues

func (sink *StandardLogSink) WithValues(keysAndValues ...any) logr.LogSink

WithValues returns a new StandardLogSink with additional key/value pairs.

type TeeHandler

type TeeHandler []slog.Handler

TeeHandler composes multiple slog.Handler instances, forwarding all function calls to each.

See https://pkg.go.dev/log/slog#Handler

func (TeeHandler) Enabled

func (tee TeeHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled tests whether all underlying sinks enables the specified level. It returns false if any does not.

See https://pkg.go.dev/log/slog#Handler

func (TeeHandler) Handle

func (tee TeeHandler) Handle(ctx context.Context, record slog.Record) error

Handle handles the given record by forwarding it to all underlying handlers.

See https://pkg.go.dev/log/slog#Handler

func (TeeHandler) WithAttrs

func (tee TeeHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new TeeHandler containing new copies of the underlying handlers with additional key/value attributes.

See https://pkg.go.dev/log/slog#Handler

func (TeeHandler) WithGroup

func (tee TeeHandler) WithGroup(name string) slog.Handler

WithGroup returns a new TeeHandler containing new copies of the underlying handlers with the specified group name appended.

See https://pkg.go.dev/log/slog#Handler

type TeeLogSink

type TeeLogSink []logr.LogSink

TeeLogSink composes multiple logr.LogSink instances, forwarding all function calls to each.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) Enabled

func (sinks TeeLogSink) Enabled(level int) bool

Enabled tests whether all underlying sinks enables the specified level. It returns false if any does not.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) Error

func (sinks TeeLogSink) Error(err error, msg string, keysAndValues ...any)

Error logs an error on all underlying sinks.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) Info

func (sinks TeeLogSink) Info(level int, msg string, keysAndValues ...any)

Info logs a non-error message on all underlying sinks.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) Init

func (sinks TeeLogSink) Init(info logr.RuntimeInfo)

Init receives and forwards optional information about the logr library to all underlying sinks.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) WithName

func (sinks TeeLogSink) WithName(name string) logr.LogSink

WithName returns a new TeeSink containing new copies of the underlying sinks with the specified name appended.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

func (TeeLogSink) WithValues

func (sinks TeeLogSink) WithValues(keysAndValues ...any) logr.LogSink

WithValues returns a new TeeSink containing new copies of the underlying sinks with additional key/value pairs.

See https://pkg.go.dev/github.com/go-logr/logr#LogSink

Jump to

Keyboard shortcuts

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