consumer

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package consumer provides the functionally to print log events either to console, files, ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aware

type Aware interface {
	// GetConsumer returns the current consumer.
	GetConsumer() Consumer
}

Aware describes an object that is aware of a Consumer and exports its current state.

type Consumer

type Consumer interface {
	// Consume consumes the event.
	Consume(event log.Event, source log.CoreLogger)
}

Consumer consumes instances of log.Event of a log.CoreLogger and for example print them to the console, to files, ...

var Default Consumer = NewWriter(os.Stderr)

Default is the default instance of Consumer which should cover the majority of all cases.

func NewFacade added in v0.9.0

func NewFacade(provider func() Consumer) Consumer

NewFacade creates a new facade of Consumer with the given function that provides the actual Consumer to use.

func Noop added in v0.9.0

func Noop() Consumer

Noop provides a noop implementation of Consumer.

type Func added in v0.9.0

type Func func(event log.Event, source log.CoreLogger)

Func is wrapping a given function into an instance of Consumer.

func (Func) Consume added in v0.9.0

func (instance Func) Consume(event log.Event, source log.CoreLogger)

Consume implements Consumer.Consume()

type MutableAware added in v0.20.0

type MutableAware interface {
	Aware

	// SetConsumer modifies the current consumer to the given one.
	SetConsumer(Consumer)
}

MutableAware is similar to Aware but additionally is able to modify the Consumer by calling SetConsumer(Consumer).

type Recorder added in v0.10.0

type Recorder struct {
	// Synchronized defines if this instance can be used in concurrent
	// environments; which is meaningful in the most context. It might have
	// additional performance costs.
	Synchronized bool
	// contains filtered or unexported fields
}

Recorder is an implementation of a Consumer which only records all logged events and makes it able to Get() them afterwards from this Recorder.

func NewRecorder added in v0.10.0

func NewRecorder(customizer ...func(*Recorder)) *Recorder

NewRecorder creates a new instance of Recorder which can be customized using customizer and is ready to use. The created instance is synchronized by default (See Recorder.Synchronized).

func (*Recorder) Consume added in v0.10.0

func (instance *Recorder) Consume(event log.Event, _ log.CoreLogger)

Consume implements Consumer.Consume()

func (*Recorder) Get added in v0.10.0

func (instance *Recorder) Get(index uint) log.Event

Get return an event at the given index. If this index does not exists this method will panic.

func (*Recorder) GetAll added in v0.10.0

func (instance *Recorder) GetAll() []log.Event

GetAll returns all recorded events.

func (*Recorder) Len added in v0.10.0

func (instance *Recorder) Len() int

Len returns the amount of recorded events so far.

func (*Recorder) Reset added in v0.10.0

func (instance *Recorder) Reset()

Reset will remove all recorded events of this Consumer.

type Writer added in v0.9.0

type Writer struct {
	// Formatter to format the consumed log.Event with. If nothing was provided
	// formatter.Default will be used.
	Formatter formatter.Formatter

	// Interceptor can be used to intercept the consumption of an event shortly
	// before the actual consumption or directly afterward. If nothing was
	// provided interceptor.Default will be used.
	Interceptor interceptor.Interceptor

	// HintsProvider is used to determine an instance of hints.Hints for the
	// actual log.Event. These might be used by the actual Formatter to know how
	// to format the actual log.Event correctly. This could include of
	// colorization is supported and demanded or any other stuff. If nothing was
	// provided a default instance will be provided which provides:
	// 1. hints.ColorsSupport
	HintsProvider func(event log.Event, source log.CoreLogger) hints.Hints

	// Synchronized defines if this instance can be used in concurrent
	// environments; which is meaningful in the most context. It might have
	// additional performance costs.
	Synchronized bool

	// OnFormatError will be called if their as any kind of error while
	// formatting an log.Event using the configured Formatter. If nothing was
	// provided these errors will result in a fallback message of the event.
	OnFormatError func(*Writer, io.Writer, error)

	// OnColorInitializationError will be called if their as any kind of error
	// while initialize the color support. If nothing was provided these errors
	// will be silently swallowed.
	OnColorInitializationError func(*Writer, io.Writer, error)
	// contains filtered or unexported fields
}

Writer is an implementation of Writer which formats the consumed log.Entry using a configured Formatter and logs it to the configured io.Writer.

NewWriter() is used to create a new instance.

func NewWriter added in v0.9.0

func NewWriter(out io.Writer, customizer ...func(*Writer)) *Writer

NewWriter creates a new instance of Writer which can be customized using customizer and is ready to use. The created instance is synchronized by default (See Writer.Synchronized).

func (*Writer) Consume added in v0.9.0

func (instance *Writer) Consume(event log.Event, source log.CoreLogger)

Consume implements Consumer.Consume()

func (*Writer) GetFormatter added in v0.20.0

func (instance *Writer) GetFormatter() formatter.Formatter

GetFormatter implements formatter.Aware

func (*Writer) GetOut added in v0.20.0

func (instance *Writer) GetOut() io.Writer

GetOut returns the actual io.Writer where the output will be written to.

func (*Writer) SetFormatter added in v0.20.0

func (instance *Writer) SetFormatter(v formatter.Formatter)

SetFormatter implements formatter.MutableAware

Jump to

Keyboard shortcuts

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