logr

package
v0.0.0-...-f7cdbce Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logr provides a logr.LogSink implementation that sends log entries to a Loki instance.

Index

Constants

View Source
const (
	// ErrorKey is the key added to the structured metadata when an error is logged. Its value is the stringified
	// error.
	ErrorKey = "error"
	// LevelKey is the key added to the stream labels for a log line. For errors, it will be -1.
	LevelKey = "level"
	// NameKey is the key added to the stream labels for a log line. Its value is the names of the
	// logger joined by "/".
	NameKey = "name"
	// SourceKey is the prefix for the keys added to the structured metadata when a log line is logged. The actual
	// keys used are SourceKey+"_function", SourceKey+"_file", and SourceKey+"_line".
	SourceKey = "source"
)

Variables

This section is empty.

Functions

func New

func New(lokiClient client.Client, level ...int) *logr.Logger

New creates a new logr.Logger with the given client and level. Optionally, it can be configured with the given level. If multiple levels are provided, the sink will log only messages less than or equal to the first level provided. It is safe to call concurrently from multiple goroutines, even if the client is shared.

For more control over the sink, use NewLokiSink instead and create a logr.Logger with that sink.

sink := NewLokiSink(lokiClient, level)
// ...configure sink...
logger := logr.New(sink)

Types

type LokiSink

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

LokiSink is a logr.LogSink that sends log entries to a Loki instance. Any keys and values added to the logr.Logger (and thus this sink) will be added as stream labels. Any keys and values set when calling a logging function will be added as structured metadata.

func NewLokiSink

func NewLokiSink(lokiClient client.Client, level ...int) *LokiSink

NewLokiSink creates a new LokiSink with the given client. Optionally, it can be configured with the given level. If multiple levels are provided, the sink will log only messages less than or equal to the first level provided. It is safe to call concurrently from multiple goroutines, even if the client is shared.

func (*LokiSink) Clone

func (sink *LokiSink) Clone() *LokiSink

Clone returns a copy of the sink. Only the client is shared. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) Enabled

func (sink *LokiSink) Enabled(level int) bool

Enabled reports whether the sink is enabled for the given level, i.e. whether the provided level is less than or equal to the sink's level. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) Error

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

Error logs the message with the provided error and level. It adds the level set to -1 to the stream labels and the keys and values to the structured metadata. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) Info

func (sink *LokiSink) Info(level int, msg string, keysAndValues ...any)

Info logs the message with the provided level. It adds the level to the stream labels and the keys and values to the structured metadata. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) Init

func (sink *LokiSink) Init(info logr.RuntimeInfo)

Init allows the sink to be initialized with the given logr.RuntimeInfo. It modifies the sink in place.

func (*LokiSink) WithCallDepth

func (sink *LokiSink) WithCallDepth(depth int) logr.LogSink

WithCallDepth returns a new LokiSink with the given call depth offset as specified by the logr.CallDepthLogSink interface. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) WithLevel

func (sink *LokiSink) WithLevel(level int) *LokiSink

WithLevel returns a new LokiSink with the given level. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) WithName

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

WithName returns a new LokiSink with the given name joined to the existing names in the stream labels by a `/`. It is safe to call concurrently from multiple goroutines.

func (*LokiSink) WithValues

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

WithValues returns a new LokiSink with the given keys and values added to the stream labels. If there are an odd number of keys and values, the last value is ignored. It is safe to call concurrently from multiple goroutines.

Jump to

Keyboard shortcuts

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