log

package
v0.0.0-...-a57c3b5 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

This package provides the generic logging interface; it is broadly compatible with logrus, which is itself generally compatible with the standard library logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithFields

func ContextWithFields(ctx context.Context, fields Fields) context.Context

This is mostly for use by LogProviders; adds fields to a raw context.Context If you're looking to derive from the default ContextLogger, you want log.WithFields

func ContextWithStack

func ContextWithStack(ctx context.Context, stack []uintptr) context.Context

func Debug

func Debug(args ...interface{})

func DebugReport

func DebugReport(args ...interface{})

func DefaultProvider

func DefaultProvider() providers.LogProvider

func Error

func Error(args ...interface{})

func ErrorReport

func ErrorReport(args ...interface{})

func Info

func Info(args ...interface{})

func InfoReport

func InfoReport(args ...interface{})

func Record

func Record(metrics Metrics)

func RecordEvent

func RecordEvent(eventName string, metrics Metrics)

func SetDefaultProvider

func SetDefaultProvider(provider providers.LogProvider)

func StackFromContext

func StackFromContext(ctx context.Context) []uintptr

func Wait

func Wait()

func Warn

func Warn(args ...interface{})

func WarnReport

func WarnReport(args ...interface{})

Types

type ComposableLogger

type ComposableLogger interface {
	LogProvider() providers.LogProvider

	/* Methods passed through to LogProvider with added context */
	ErrorReport(args ...interface{})
	Error(args ...interface{})
	WarnReport(args ...interface{})
	Warn(args ...interface{})
	InfoReport(args ...interface{})
	Info(args ...interface{})
	DebugReport(args ...interface{})
	Debug(args ...interface{})
	Record(metrics Metrics)
	RecordEvent(eventName string, metrics Metrics)

	// Add log data to a context to be used with future log messages
	WithField(key string, val interface{}) ContextLogger
	WithFields(fields Fields) ContextLogger
}

This can be combined with an object that already supplies context.Context, without conflict, to create a ContextLogger; it's not really intended to be used standalone, and in most cases you probably want to include ContextLogger rather than this in other interfaces/structs.

In particular, if you are composing this with another supplier of Context, you need to keep in mind that a ContextLogger using the implementation in this file won't have access to your Context that lives next to it. So usually what you would want to do instead is use an interface to mask out the Context part of the ContextLogger's neighbor, then derive the ContextLogger instance from the source object that you've masked the context out of for composition.

TODO: show example of what I'm talking about

type ContextLogger

type ContextLogger interface {
	context.Context
	ComposableLogger
}

ContextLoggers are designed to be passed around for convenience within a given project; APIs which are meant to be used from other projects should use the standard golang context.Context interface instead, for broad compatibility. You can always recover a ContextLogger from a Context using FromContext below.

func BackgroundContext

func BackgroundContext() ContextLogger

func FromContext

func FromContext(ctx context.Context) ContextLogger

func FromContextAndProvider

func FromContextAndProvider(ctx context.Context, provider providers.LogProvider) ContextLogger

func WithField

func WithField(key string, val interface{}) ContextLogger

func WithFields

func WithFields(fields Fields) ContextLogger

type Fields

type Fields map[string]interface{}

func FieldsFromContext

func FieldsFromContext(ctx context.Context) Fields

type Metrics

type Metrics map[string]interface{}

Jump to

Keyboard shortcuts

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