micrologger

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: Apache-2.0 Imports: 10 Imported by: 2,426

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 = func() interface{} {
	return fmt.Sprintf("%+v", stack.Caller(4))
}
View Source
var DefaultIOWriter = os.Stdout
View Source
var DefaultTimestampFormatter = 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 {
	// Log takes a sequence of alternating key/value pairs which are used
	// to create the log message structure.
	Log(keyVals ...interface{}) error
	// 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{}) error
	// 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
}

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 MicroLogger

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

func New

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

func (*MicroLogger) Log

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

func (*MicroLogger) LogCtx

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

func (*MicroLogger) With

func (l *MicroLogger) With(keyVals ...interface{}) 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