Documentation
¶
Overview ¶
Package logr provides a logr.LogSink implementation that sends log entries to a Loki instance.
Index ¶
- Constants
- func New(lokiClient client.Client, level ...int) *logr.Logger
- type LokiSink
- func (sink *LokiSink) Clone() *LokiSink
- func (sink *LokiSink) Enabled(level int) bool
- func (sink *LokiSink) Error(err error, msg string, keysAndValues ...any)
- func (sink *LokiSink) Info(level int, msg string, keysAndValues ...any)
- func (sink *LokiSink) Init(info logr.RuntimeInfo)
- func (sink *LokiSink) WithCallDepth(depth int) logr.LogSink
- func (sink *LokiSink) WithLevel(level int) *LokiSink
- func (sink *LokiSink) WithName(name string) logr.LogSink
- func (sink *LokiSink) WithValues(keysAndValues ...any) logr.LogSink
Constants ¶
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 ¶
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 ¶
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 ¶
Clone returns a copy of the sink. Only the client is shared. It is safe to call concurrently from multiple goroutines.
func (*LokiSink) Enabled ¶
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 ¶
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 ¶
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 ¶
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 ¶
WithLevel returns a new LokiSink with the given level. It is safe to call concurrently from multiple goroutines.
func (*LokiSink) WithName ¶
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 ¶
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.