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 ¶
- type OpenTelemetryHandler
- func (handler *OpenTelemetryHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (handler *OpenTelemetryHandler) Handle(ctx context.Context, rec slog.Record) error
- func (handler *OpenTelemetryHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (handler *OpenTelemetryHandler) WithGroup(name string) slog.Handler
- type OpenTelemetryLogSink
- func (*OpenTelemetryLogSink) Enabled(_ int) bool
- func (sink *OpenTelemetryLogSink) Error(err error, msg string, keysAndValues ...any)
- func (sink *OpenTelemetryLogSink) Info(_ int, msg string, keysAndValues ...any)
- func (*OpenTelemetryLogSink) Init(_ logr.RuntimeInfo)
- func (sink *OpenTelemetryLogSink) WithName(name string) logr.LogSink
- func (sink *OpenTelemetryLogSink) WithValues(keysAndValues ...any) logr.LogSink
- type StandardLogSink
- func (*StandardLogSink) Enabled(_ int) bool
- func (sink *StandardLogSink) Error(err error, msg string, keysAndValues ...any)
- func (sink *StandardLogSink) Info(_ int, msg string, keysAndValues ...any)
- func (*StandardLogSink) Init(_ logr.RuntimeInfo)
- func (sink *StandardLogSink) WithName(name string) logr.LogSink
- func (sink *StandardLogSink) WithValues(keysAndValues ...any) logr.LogSink
- type TeeHandler
- type TeeLogSink
- func (sinks TeeLogSink) Enabled(level int) bool
- func (sinks TeeLogSink) Error(err error, msg string, keysAndValues ...any)
- func (sinks TeeLogSink) Info(level int, msg string, keysAndValues ...any)
- func (sinks TeeLogSink) Init(info logr.RuntimeInfo)
- func (sinks TeeLogSink) WithName(name string) logr.LogSink
- func (sinks TeeLogSink) WithValues(keysAndValues ...any) logr.LogSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OpenTelemetryHandler ¶
OpenTelemetryHandler is a slog.Handler that emits OpenTelemetry log records.
See https://pkg.go.dev/log/slog#Handler
func (*OpenTelemetryHandler) Enabled ¶
Enabled returns true if the OpenTelemetry logger emits records for this context and level.
func (*OpenTelemetryHandler) Handle ¶
Handle emits an OpenTelemetry log entry with the data from the record.
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 ¶
func (*OpenTelemetryLogSink) Init(_ logr.RuntimeInfo)
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 ¶
TeeHandler composes multiple slog.Handler instances, forwarding all function calls to each.
See https://pkg.go.dev/log/slog#Handler
func (TeeHandler) Enabled ¶
Enabled tests whether all underlying sinks enables the specified level. It returns false if any does not.
func (TeeHandler) Handle ¶
Handle handles the given record by forwarding it to all underlying handlers.
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.
type TeeLogSink ¶
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.
func (TeeLogSink) Error ¶
func (sinks TeeLogSink) Error(err error, msg string, keysAndValues ...any)
Error logs an error on all underlying sinks.
func (TeeLogSink) Info ¶
func (sinks TeeLogSink) Info(level int, msg string, keysAndValues ...any)
Info logs a non-error message on all underlying sinks.
func (TeeLogSink) Init ¶
func (sinks TeeLogSink) Init(info logr.RuntimeInfo)
Init receives and forwards optional information about the logr library to all underlying sinks.
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.
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.