function

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

Package function provides an implementation of the telemetry.Logger interface that uses a given function to emit logs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(emitFunc Emit) telemetry.Logger

NewLogger creates a new function Logger that uses the given Emit function to write log messages. Loggers are configured at telemetry.LevelInfo level by default.

Types

type Emit

type Emit func(level telemetry.Level, msg string, err error, values Values)

Emit is a function that will be used to produce log messages by the function Logger. Implementations of this function just need to implement the log writing. Decisions on whether to emit a log or not based on the log level should not be made here as the function Logger already takes care of that. Similarly, the keyValues parameter presented in this method will already contain al the key/value pairs that need to be logged. The function will only be called when the log actually needs to be emitted.

type Logger

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

Logger is an implementation of the telemetry.Logger that allows configuring named loggers that can be configured independently and referenced by name.

func (*Logger) Clone

func (l *Logger) Clone() telemetry.Logger

Clone the current Logger and return it

func (*Logger) Context

func (l *Logger) Context(ctx context.Context) telemetry.Logger

Context attaches provided Context to the Logger allowing metadata found in this context to be used for log lines and metrics labels.

func (*Logger) Debug

func (l *Logger) Debug(msg string, keyValues ...interface{})

Debug emits a log message at debug level with the given key value pairs.

func (*Logger) Error

func (l *Logger) Error(msg string, err error, keyValues ...interface{})

Error emits a log message at error level with the given key value pairs. The given error will be used as the last parameter in the message format string.

func (*Logger) Info

func (l *Logger) Info(msg string, keyValues ...interface{})

Info emits a log message at info level with the given key value pairs.

func (*Logger) Level

func (l *Logger) Level() telemetry.Level

Level returns the logging level configured for this Logger.

func (*Logger) Metric

func (l *Logger) Metric(m telemetry.Metric) telemetry.Logger

Metric attaches provided Metric to the Logger allowing this metric to record each invocation of Info and Error log lines. If context is available in the Logger, it can be used for Metrics labels.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level telemetry.Level)

SetLevel configures the logging level for the Logger.

func (*Logger) With

func (l *Logger) With(keyValues ...interface{}) telemetry.Logger

With returns Logger with provided key value pairs attached.

type Values

type Values struct {
	// FromContext has all the key/value pairs that have been added to the Logger Context
	FromContext []interface{}
	// FromLogger has all the key/value pairs that have been added to the Logger object itself
	FromLogger []interface{}
	// FromMethod has the key/value pairs that were passed to the logging method.
	FromMethod []interface{}
}

Values contains all the key/value pairs to be included when emitting logs.

Jump to

Keyboard shortcuts

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