interceptor

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Interceptors are used to intercept instances of log.Event that are requested to be logged. It can modify events (before they get logged) or even fully prevents to get logged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fatal

type Fatal struct {
	// ExitCode to exit the application with.
	ExitCode int
}

Fatal will exit the application after logged events on level.Fatal.

func NewFatal added in v0.9.0

func NewFatal(customizer ...func(*Fatal)) *Fatal

NewFatal creates a new instance of Fatal.

func (*Fatal) GetPriority added in v0.9.0

func (instance *Fatal) GetPriority() int16

GetPriority implements Interceptor.GetPriority()

func (*Fatal) OnAfterLog

func (instance *Fatal) OnAfterLog(event log.Event, _ log.Provider) (canContinue bool)

OnAfterLog implements Interceptor.OnAfterLog()

func (*Fatal) OnBeforeLog

func (instance *Fatal) OnBeforeLog(event log.Event, _ log.Provider) (intercepted log.Event)

OnBeforeLog implements Interceptor.OnBeforeLog()

type Interceptor

type Interceptor interface {
	// OnBeforeLog is called shortly before a log.Event should be logged.
	// Whatever is returned by this method will be logged (if not nil). If this
	// method returns nil logging of this event will be skipped and calling of
	// other interceptors will be skipped, too.
	OnBeforeLog(log.Event, log.Provider) (intercepted log.Event)

	// OnAfterLog is called shortly after a log.Event was logged. If canContinue
	// is false no other Interceptor will be called afterwards.
	OnAfterLog(log.Event, log.Provider) (canContinue bool)

	// GetPriority defines the order how all interceptors will be called. As
	// lower this value is, as earlier this Interceptor will be called.
	GetPriority() int16
}

Interceptor is used to intercept instances of log.Event that are requested to be logged. It can modify events (before they get logged) or even fully prevents to get logged.

func NewFacade added in v0.9.0

func NewFacade(provider func() Interceptor) Interceptor

NewFacade creates a facade of Interceptor using the given provider.

func Noop

func Noop() Interceptor

Noop provides a noop implementation of Interceptor.

type Interceptors

type Interceptors []Interceptor

Interceptors is a collection of several interceptors.

Add() should be used to modify this instance because it will ensure the correct order of all interceptors when this one is called.

var Default Interceptors = Interceptors{}

Default is the default instance of Interceptors which should cover the most of the cases.

func (*Interceptors) Add added in v0.4.0

func (instance *Interceptors) Add(v Interceptor) *Interceptors

Add appends a given Interceptor to this instance and ensures that everything inside is ordered according to Interceptor.GetPriority().

func (Interceptors) GetPriority added in v0.4.0

func (instance Interceptors) GetPriority() int16

GetPriority implements Interceptor.GetPriority() and will return the lowest priority of all contained interceptors.

func (Interceptors) Len added in v0.4.0

func (instance Interceptors) Len() int

Len provides the length of this instance.

func (Interceptors) Less added in v0.4.0

func (instance Interceptors) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (Interceptors) OnAfterLog

func (instance Interceptors) OnAfterLog(event log.Event, provider log.Provider) (canContinue bool)

OnAfterLog implements Interceptor.OnAfterLog()

func (Interceptors) OnBeforeLog

func (instance Interceptors) OnBeforeLog(event log.Event, provider log.Provider) (intercepted log.Event)

OnBeforeLog implements Interceptor.OnBeforeLog()

func (Interceptors) Swap added in v0.4.0

func (instance Interceptors) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type OnAfterLogFunc added in v0.9.0

type OnAfterLogFunc func(event log.Event, provider log.Provider) (canContinue bool)

OnAfterLogFunc is a shortcut to Interceptor.OnAfterLog().

func (OnAfterLogFunc) GetPriority added in v0.9.0

func (instance OnAfterLogFunc) GetPriority() int16

GetPriority implements Interceptor.GetPriority().

func (OnAfterLogFunc) OnAfterLog added in v0.9.0

func (instance OnAfterLogFunc) OnAfterLog(event log.Event, provider log.Provider) bool

OnAfterLog implements Interceptor.OnAfterLog().

func (OnAfterLogFunc) OnBeforeLog added in v0.9.0

func (instance OnAfterLogFunc) OnBeforeLog(event log.Event, _ log.Provider) log.Event

OnBeforeLog implements Interceptor.OnBeforeLog().

type OnBeforeLogFunc added in v0.9.0

type OnBeforeLogFunc func(event log.Event, provider log.Provider) (intercepted log.Event)

OnBeforeLogFunc is a shortcut to Interceptor.OnBeforeLog().

func (OnBeforeLogFunc) GetPriority added in v0.9.0

func (instance OnBeforeLogFunc) GetPriority() int16

GetPriority implements Interceptor.GetPriority().

func (OnBeforeLogFunc) OnAfterLog added in v0.9.0

func (instance OnBeforeLogFunc) OnAfterLog(log.Event, log.Provider) bool

OnAfterLog implements Interceptor.OnAfterLog().

func (OnBeforeLogFunc) OnBeforeLog added in v0.9.0

func (instance OnBeforeLogFunc) OnBeforeLog(event log.Event, provider log.Provider) log.Event

OnBeforeLog implements Interceptor.OnBeforeLog().

Jump to

Keyboard shortcuts

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