micrologger

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 13 Imported by: 2,295

README

CircleCI Go Report Card IRC Channel

micrologger

This is a logging library we use at Giant Swarm for many of our operators and microservices.

Documentation

Overview

Package logger implements a logging interface used to log messages.

Index

Constants

View Source
const (
	KeyLevel     = "level"
	KeyVerbosity = "verbosity"
)

Variables

View Source
var DefaultCaller = newCallerFunc(0)
View Source
var DefaultIOWriter = os.Stdout
View Source
var DefaultTimestampFormatter kitlog.Valuer = func() interface{} {
	return time.Now().UTC().Format("2006-01-02T15:04:05.999999-07:00")
}

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

Types

type ActivationLoggerConfig

type ActivationLoggerConfig struct {
	Underlying Logger

	Activations map[string]interface{}
}

type Config

type Config struct {
	Caller             kitlog.Valuer
	IOWriter           io.Writer
	TimestampFormatter kitlog.Valuer
}

type Logger

type Logger interface {
	// Debug writes the given message in debug level.
	Debug(ctx context.Context, message string)
	// Debugf takes a format string and parameters and writes them in debug level.
	Debugf(ctx context.Context, format string, params ...interface{})
	// Error takes an error and a message and writes them in error level. The
	// error stack trace is written as "stack" value log entry.
	Error(ctx context.Context, err error, message string)
	// Errorf takes an error, a format string and parameters and writes them in
	// error level. The error stack trace is written as "stack" value log
	// entry.
	Errorf(ctx context.Context, err error, format string, params ...interface{})
	// Log takes a sequence of alternating key/value pairs which are used
	// to create the log message structure.
	Log(keyVals ...interface{})
	// LogCtx is the same as Log but additionally taking a context which
	// may contain additional key-value pairs that are added to the log
	// issuance, if any.
	LogCtx(ctx context.Context, keyVals ...interface{})
	// With returns a new contextual logger with keyVals appended to those
	// passed to calls to Log. If logger is also a contextual logger
	// created by With, keyVals is appended to the existing context.
	With(keyVals ...interface{}) Logger
	// WithIncreasedCallerDepth is useful when wrapping with another
	// interface to pass it as dependency to a library outside Giant Swarm.
	WithIncreasedCallerDepth() Logger
}

Logger is a simple interface describing services that emit messages to gather certain runtime information.

func NewActivation

func NewActivation(config ActivationLoggerConfig) (Logger, error)

NewActivation creates a new activation key logger. This logger kind can be used on command line tools to improve situations in which log filtering using other command line tools like grep is not sufficient. Due to certain filter mechanisms this Logger implementation should not be used in performance critical applications. The idea of the activation key logger is to have a multi dimensional log filter mechanism. This logger here provides three different features which can be combined and used simultaneously at will.

Filtering arbitrary key-value pairs. The structured nature of the Logger
interface expects key-value pairs to be logged. The activation key logger
can be configured with any kind of activation key-pairs which, when
configured, all have to match against an emitted logging call, in order
to be dispatched. In case none, or not all activation keys match, the
emitted logging call is going to be ignored.

Filtering log levels works using the special log levels debug, info,
warning and error. The level based nature of this activation mechanism is
that lower log levels match just like exact log levels match. When the
Logger is configured to activate on info log levels, the Logger will
activate on debug related logs, as well as info related logs, but not on
warning or error related logs.

Filtering log verbosity works similar like the log level mechanism, but
on arbitrary verbosity levels, which are represented as numbers. As long
as the configured verbosity is higher or equal to the perceived verbosity
obtained by the emitted logging call, the log will be dispatched.

type LogrSink added in v1.0.0

type LogrSink struct {
	*MicroLogger
}

func (*LogrSink) Enabled added in v1.0.0

func (l *LogrSink) Enabled(level int) bool

func (*LogrSink) Error added in v1.0.0

func (l *LogrSink) Error(err error, msg string, keysAndValues ...interface{})

func (*LogrSink) Info added in v1.0.0

func (l *LogrSink) Info(level int, msg string, keysAndValues ...interface{})

func (*LogrSink) Init added in v1.0.0

func (l *LogrSink) Init(info logr.RuntimeInfo)

func (*LogrSink) WithName added in v1.0.0

func (l *LogrSink) WithName(name string) logr.LogSink

func (*LogrSink) WithValues added in v1.0.0

func (l *LogrSink) WithValues(keysAndValues ...interface{}) logr.LogSink

type MicroLogger

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

func New

func New(config Config) (*MicroLogger, error)

func (*MicroLogger) AsSink added in v1.0.0

func (l *MicroLogger) AsSink(verbosity int) logr.LogSink

func (*MicroLogger) Debug added in v1.0.0

func (l *MicroLogger) Debug(ctx context.Context, message string)

func (*MicroLogger) Debugf added in v0.4.0

func (l *MicroLogger) Debugf(ctx context.Context, format string, params ...interface{})

func (*MicroLogger) Error added in v1.0.0

func (l *MicroLogger) Error(ctx context.Context, err error, message string)

func (*MicroLogger) Errorf added in v0.4.0

func (l *MicroLogger) Errorf(ctx context.Context, err error, format string, params ...interface{})

func (*MicroLogger) Log

func (l *MicroLogger) Log(keyVals ...interface{})

func (*MicroLogger) LogCtx

func (l *MicroLogger) LogCtx(ctx context.Context, keyVals ...interface{})

func (*MicroLogger) With

func (l *MicroLogger) With(keyVals ...interface{}) Logger

func (*MicroLogger) WithIncreasedCallerDepth added in v0.5.0

func (l *MicroLogger) WithIncreasedCallerDepth() Logger

Directories

Path Synopsis
Package loggermeta stores and accesses the container struct in context.Context.
Package loggermeta stores and accesses the container struct in context.Context.

Jump to

Keyboard shortcuts

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