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 ¶
- func ContextWithFields(ctx context.Context, fields Fields) context.Context
- func ContextWithStack(ctx context.Context, stack []uintptr) context.Context
- func Debug(args ...interface{})
- func DebugReport(args ...interface{})
- func DefaultProvider() providers.LogProvider
- func Error(args ...interface{})
- func ErrorReport(args ...interface{})
- func Info(args ...interface{})
- func InfoReport(args ...interface{})
- func Record(metrics Metrics)
- func RecordEvent(eventName string, metrics Metrics)
- func SetDefaultProvider(provider providers.LogProvider)
- func StackFromContext(ctx context.Context) []uintptr
- func Wait()
- func Warn(args ...interface{})
- func WarnReport(args ...interface{})
- type ComposableLogger
- type ContextLogger
- type Fields
- type Metrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithFields ¶
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 DebugReport ¶
func DebugReport(args ...interface{})
func DefaultProvider ¶
func DefaultProvider() providers.LogProvider
func ErrorReport ¶
func ErrorReport(args ...interface{})
func InfoReport ¶
func InfoReport(args ...interface{})
func RecordEvent ¶
func SetDefaultProvider ¶
func SetDefaultProvider(provider providers.LogProvider)
func StackFromContext ¶
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